From 7cf6f9bd949672ef926c2754673fba8ae43d0787 Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Tue, 17 Dec 2024 07:04:15 +0000 Subject: [PATCH] refactor: command 'nextcloud card get' takes board id from parameters --- README.md | 2 +- src/nextcloud/card.rs | 46 ++++++++++++++------------------- src/nextcloud/tests/card/get.rs | 4 ++- 3 files changed, 24 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 05642f3..8c7c296 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ As part of building the import server, the following commands exercise each oper - [x] nextcloud deck get - includes list of boards - [x] nextcloud board get - includes list of stacks - [x] nextcloud stack get - includes list of cards -- [ ] nextcloud card get - shows card title +- [x] nextcloud card get - shows card title - [ ] nextcloud card create - [ ] nextcloud card add-label - [ ] nextcloud card add-attachment \ No newline at end of file diff --git a/src/nextcloud/card.rs b/src/nextcloud/card.rs index 977996e..56ff012 100644 --- a/src/nextcloud/card.rs +++ b/src/nextcloud/card.rs @@ -13,6 +13,7 @@ pub enum NextcloudCardCommand { Get { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, + board_id: i64, stack_id: i64, card_id: i64, }, @@ -40,16 +41,28 @@ impl Execute for NextcloudCardCommand { match self { Self::Get { dump, + board_id, stack_id, card_id, } => { - get( - ctx, - *dump, - NextcloudStackId::from(*stack_id), - NextcloudCardId::from(*card_id), - ) - .await + let api_result = ctx + .deck_client() + .get_card((*board_id).into(), (*stack_id).into(), (*card_id).into()) + .await; + if *dump { + p!(ctx.prt, "{}", api_result.text); + } else { + let card = api_result.result?; + p!( + ctx.prt, + "{}:{}:{}:{}", + board_id, + stack_id, + card_id, + card.title + ); + } + Ok(()) } Self::Create { dump, @@ -89,25 +102,6 @@ impl Execute for NextcloudCardCommand { } } -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(()) -} - pub(crate) struct Create { pub(crate) dump: bool, pub(crate) stack_id: NextcloudStackId, diff --git a/src/nextcloud/tests/card/get.rs b/src/nextcloud/tests/card/get.rs index f88d6f6..ffe30c5 100644 --- a/src/nextcloud/tests/card/get.rs +++ b/src/nextcloud/tests/card/get.rs @@ -51,6 +51,7 @@ async fn dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCardId //when Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get { dump: true, + board_id: ctx.cfg.nextcloud.board_id.into(), stack_id: stack_id.into(), card_id: card_id.into(), })) @@ -76,6 +77,7 @@ async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCar //when Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get { dump: false, + board_id: ctx.cfg.nextcloud.board_id.into(), stack_id: stack_id.into(), card_id: card_id.into(), })) @@ -85,5 +87,5 @@ async fn no_dump(ctx: FullCtx, stack_id: NextcloudStackId, card_id: NextcloudCar //then let output = prt.output(); - assert_peq!(output.trim(), "321:Breakfast: Cereal"); + assert_peq!(output.trim(), "2:1:321:Breakfast: Cereal"); }