refactor: command 'nextcloud card add-label'
Some checks failed
Release Please / Release-plz (push) Failing after 22s
Test / build (map[name:nightly]) (push) Successful in 2m12s
Test / build (map[name:stable]) (push) Successful in 2m28s

This commit is contained in:
Paul Campbell 2024-12-17 07:19:31 +00:00
parent 8598de6976
commit 36a2258bc6
5 changed files with 31 additions and 44 deletions

View file

@ -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

View file

@ -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(())
}

View file

@ -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!({

View file

@ -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(),

View file

@ -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,