diff --git a/README.md b/README.md index 8c7c296..da10c79 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,6 @@ As part of building the import server, the following commands exercise each oper - [x] nextcloud board get - includes list of stacks - [x] nextcloud stack get - includes list of cards - [x] nextcloud card get - shows card title -- [ ] nextcloud card create -- [ ] nextcloud card add-label +- [x] nextcloud card create +- [x] 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 1998243..4ae1d8c 100644 --- a/src/nextcloud/card.rs +++ b/src/nextcloud/card.rs @@ -1,12 +1,7 @@ // use clap::Parser; -use crate::execute::Execute; -use crate::nextcloud::model::NextcloudLabelId; -use crate::{ - nextcloud::model::{NextcloudCardId, NextcloudStackId}, - p, FullCtx, -}; +use crate::{execute::Execute, p, FullCtx}; #[derive(Parser, Debug)] pub enum NextcloudCardCommand { @@ -31,6 +26,7 @@ pub enum NextcloudCardCommand { AddLabel { #[clap(long, action = clap::ArgAction::SetTrue)] dump: bool, + board_id: i64, stack_id: i64, card_id: i64, label_id: i64, @@ -98,35 +94,25 @@ impl Execute for NextcloudCardCommand { } Self::AddLabel { dump, + board_id, stack_id, card_id, label_id, } => { - add_label( - ctx, - AddLabel { - dump: *dump, - stack_id: NextcloudStackId::from(*stack_id), - card_id: NextcloudCardId::from(*card_id), - label_id: NextcloudLabelId::from(*label_id), - }, - ) - .await + let api_result = ctx + .deck_client() + .add_label_to_card( + (*board_id).into(), + (*stack_id).into(), + (*card_id).into(), + (*label_id).into(), + ) + .await; + if *dump { + p!(ctx.prt, "{}", api_result.text); + } + Ok(()) } } } } - -pub(crate) struct AddLabel { - pub(crate) dump: bool, - pub(crate) stack_id: NextcloudStackId, - pub(crate) card_id: NextcloudCardId, - pub(crate) label_id: NextcloudLabelId, -} -async fn add_label(ctx: &FullCtx, add_label: AddLabel) -> color_eyre::Result<()> { - let api_result = ctx.deck_client().add_label_to_card(&add_label).await; - if add_label.dump { - p!(ctx.prt, "{}", api_result.text); - } - Ok(()) -} diff --git a/src/nextcloud/client.rs b/src/nextcloud/client.rs index 4da76e8..e9b857a 100644 --- a/src/nextcloud/client.rs +++ b/src/nextcloud/client.rs @@ -3,15 +3,13 @@ use bytes::Bytes; use kxio::net::{Net, ReqBuilder}; use serde_json::json; +use crate::nextcloud::model::NextcloudLabelId; use crate::{ api_result::APIResult, f, - nextcloud::{ - card::AddLabel, - model::{ - Board, Card, NextcloudBoardId, NextcloudCardId, NextcloudHostname, NextcloudPassword, - NextcloudStackId, NextcloudUsername, Stack, - }, + nextcloud::model::{ + Board, Card, NextcloudBoardId, NextcloudCardId, NextcloudHostname, NextcloudPassword, + NextcloudStackId, NextcloudUsername, Stack, }, FullCtx, }; @@ -78,11 +76,13 @@ impl<'ctx> DeckClient<'ctx> { .await } - pub(crate) async fn add_label_to_card(&self, add_label: &AddLabel) -> APIResult<()> { - let board_id = self.ctx.cfg.nextcloud.board_id; - let stack_id = add_label.stack_id; - let card_id = add_label.card_id; - let label_id = add_label.label_id; + pub(crate) async fn add_label_to_card( + &self, + board_id: NextcloudBoardId, + stack_id: NextcloudStackId, + card_id: NextcloudCardId, + label_id: NextcloudLabelId, + ) -> APIResult<()> { self.request_with_body( f!("boards/{board_id}/stacks/{stack_id}/cards/{card_id}/assignLabel"), json!({ diff --git a/src/nextcloud/tests/card/add_label.rs b/src/nextcloud/tests/card/add_label.rs index b554396..5ebdd98 100644 --- a/src/nextcloud/tests/card/add_label.rs +++ b/src/nextcloud/tests/card/add_label.rs @@ -59,6 +59,7 @@ async fn dump( //when Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel { dump: true, + board_id: ctx.cfg.nextcloud.board_id.into(), stack_id: stack_id.into(), card_id: card_id.into(), label_id: label_id.into(), @@ -87,6 +88,7 @@ async fn no_dump( //when Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel { dump: false, + board_id: ctx.cfg.nextcloud.board_id.into(), stack_id: stack_id.into(), card_id: card_id.into(), label_id: label_id.into(), diff --git a/src/nextcloud/tests/mod.rs b/src/nextcloud/tests/mod.rs index 9eb7c13..ef2fd03 100644 --- a/src/nextcloud/tests/mod.rs +++ b/src/nextcloud/tests/mod.rs @@ -15,7 +15,6 @@ use crate::nextcloud::NextcloudCommand; use crate::Command; use crate::{ nextcloud::{ - card::AddLabel, model::{ Card, Label, NextcloudBoardId, NextcloudCardId, NextcloudCardTitle, NextcloudETag, NextcloudHostname, NextcloudLabelId, NextcloudOrder, NextcloudPassword,