From ecef639318e2f857b1d7201f989769556f830916 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Sat, 7 Dec 2024 09:56:40 +0000 Subject: [PATCH] feat(nextcloud): add command 'nextcloud card get' --- src/lib.rs | 11 +++++ src/nextcloud/card.rs | 25 +++++++++- src/nextcloud/mod.rs | 13 ++++++ src/tests/responses/nextcloud-card-get.json | 51 +++++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 src/tests/responses/nextcloud-card-get.json diff --git a/src/lib.rs b/src/lib.rs index 46af03c..a24f989 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -74,6 +74,12 @@ enum NextcloudCardCommand { dump: bool, stack_id: i64, }, + Get { + #[clap(long, action = clap::ArgAction::SetTrue)] + dump: bool, + stack_id: i64, + card_id: i64, + }, } #[derive(Parser, Debug)] @@ -157,6 +163,11 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> { dump, stack_id, })) => nextcloud::card::list(ctx, dump, stack_id.into()).await, + Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get { + dump, + stack_id, + card_id, + })) => nextcloud::card::get(ctx, dump, stack_id.into(), card_id.into()).await, } } } diff --git a/src/nextcloud/card.rs b/src/nextcloud/card.rs index e6ed8ac..1d89fce 100644 --- a/src/nextcloud/card.rs +++ b/src/nextcloud/card.rs @@ -1,6 +1,8 @@ // -use crate::nextcloud::model::NextcloudStackId; -use crate::{p, FullCtx}; +use crate::{ + nextcloud::model::{NextcloudCardId, NextcloudStackId}, + p, FullCtx, +}; pub(crate) async fn list( ctx: FullCtx, @@ -22,3 +24,22 @@ pub(crate) async fn list( } Ok(()) } + +pub(crate) async fn get( + ctx: FullCtx, + dump: bool, + stack_id: NextcloudStackId, + card_id: NextcloudCardId, +) -> color_eyre::Result<()> { + let api_result = ctx + .deck_client() + .get_card(ctx.cfg.nextcloud.board_id, stack_id, card_id) + .await; + if dump { + p!(ctx.prt, "{}", api_result.text); + } else { + let card = api_result.result?; + p!(ctx.prt, "{}:{}", card.id, card.title); + } + Ok(()) +} diff --git a/src/nextcloud/mod.rs b/src/nextcloud/mod.rs index e7135c1..85969bd 100644 --- a/src/nextcloud/mod.rs +++ b/src/nextcloud/mod.rs @@ -140,4 +140,17 @@ impl<'ctx> DeckClient<'ctx> { ) .await } + + async fn get_card( + &self, + board_id: NextcloudBoardId, + stack_id: NextcloudStackId, + card_id: model::NextcloudCardId, + ) -> APIResult { + self.request( + f!("boards/{board_id}/stacks/{stack_id}/cards/{card_id}"), + |net, url| net.get(url), + ) + .await + } } diff --git a/src/tests/responses/nextcloud-card-get.json b/src/tests/responses/nextcloud-card-get.json new file mode 100644 index 0000000..7ed1ca5 --- /dev/null +++ b/src/tests/responses/nextcloud-card-get.json @@ -0,0 +1,51 @@ +{ + "id": 321, + "title": "Breakfast: Cereal", + "description": "", + "stackId": 1, + "type": "plain", + "lastModified": 1733515897, + "lastEditor": null, + "createdAt": 1733043461, + "labels": [ + { + "id": 1, + "title": "Finished", + "color": "31CC7C", + "boardId": 1, + "cardId": 321, + "lastModified": 1670965629, + "ETag": "983f87848dc9c18d0aee63e7ee0fc83f" + } + ], + "assignedUsers": [ + { + "id": 24, + "participant": { + "primaryKey": "pcampbell", + "uid": "pcampbell", + "displayname": "Paul Campbell", + "type": 0 + }, + "cardId": 321, + "type": 0 + } + ], + "attachments": [], + "attachmentCount": 0, + "owner": { + "primaryKey": "pcampbell", + "uid": "pcampbell", + "displayname": "Paul Campbell", + "type": 0 + }, + "order": 1, + "archived": false, + "done": null, + "duedate": null, + "deletedAt": 0, + "commentsUnread": 0, + "commentsCount": 0, + "ETag": "bf59162abcbc193b94349985122d7009", + "overdue": 0 +}