refactor: command 'nextcloud card add-label'
This commit is contained in:
parent
8598de6976
commit
36a2258bc6
5 changed files with 31 additions and 44 deletions
|
@ -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 board get - includes list of stacks
|
||||||
- [x] nextcloud stack get - includes list of cards
|
- [x] nextcloud stack get - includes list of cards
|
||||||
- [x] nextcloud card get - shows card title
|
- [x] nextcloud card get - shows card title
|
||||||
- [ ] nextcloud card create
|
- [x] nextcloud card create
|
||||||
- [ ] nextcloud card add-label
|
- [x] nextcloud card add-label
|
||||||
- [ ] nextcloud card add-attachment
|
- [ ] nextcloud card add-attachment
|
|
@ -1,12 +1,7 @@
|
||||||
//
|
//
|
||||||
use clap::Parser;
|
use clap::Parser;
|
||||||
|
|
||||||
use crate::execute::Execute;
|
use crate::{execute::Execute, p, FullCtx};
|
||||||
use crate::nextcloud::model::NextcloudLabelId;
|
|
||||||
use crate::{
|
|
||||||
nextcloud::model::{NextcloudCardId, NextcloudStackId},
|
|
||||||
p, FullCtx,
|
|
||||||
};
|
|
||||||
|
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
pub enum NextcloudCardCommand {
|
pub enum NextcloudCardCommand {
|
||||||
|
@ -31,6 +26,7 @@ pub enum NextcloudCardCommand {
|
||||||
AddLabel {
|
AddLabel {
|
||||||
#[clap(long, action = clap::ArgAction::SetTrue)]
|
#[clap(long, action = clap::ArgAction::SetTrue)]
|
||||||
dump: bool,
|
dump: bool,
|
||||||
|
board_id: i64,
|
||||||
stack_id: i64,
|
stack_id: i64,
|
||||||
card_id: i64,
|
card_id: i64,
|
||||||
label_id: i64,
|
label_id: i64,
|
||||||
|
@ -98,35 +94,25 @@ impl Execute for NextcloudCardCommand {
|
||||||
}
|
}
|
||||||
Self::AddLabel {
|
Self::AddLabel {
|
||||||
dump,
|
dump,
|
||||||
|
board_id,
|
||||||
stack_id,
|
stack_id,
|
||||||
card_id,
|
card_id,
|
||||||
label_id,
|
label_id,
|
||||||
} => {
|
} => {
|
||||||
add_label(
|
let api_result = ctx
|
||||||
ctx,
|
.deck_client()
|
||||||
AddLabel {
|
.add_label_to_card(
|
||||||
dump: *dump,
|
(*board_id).into(),
|
||||||
stack_id: NextcloudStackId::from(*stack_id),
|
(*stack_id).into(),
|
||||||
card_id: NextcloudCardId::from(*card_id),
|
(*card_id).into(),
|
||||||
label_id: NextcloudLabelId::from(*label_id),
|
(*label_id).into(),
|
||||||
},
|
)
|
||||||
)
|
.await;
|
||||||
.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(())
|
|
||||||
}
|
|
||||||
|
|
|
@ -3,15 +3,13 @@ use bytes::Bytes;
|
||||||
use kxio::net::{Net, ReqBuilder};
|
use kxio::net::{Net, ReqBuilder};
|
||||||
use serde_json::json;
|
use serde_json::json;
|
||||||
|
|
||||||
|
use crate::nextcloud::model::NextcloudLabelId;
|
||||||
use crate::{
|
use crate::{
|
||||||
api_result::APIResult,
|
api_result::APIResult,
|
||||||
f,
|
f,
|
||||||
nextcloud::{
|
nextcloud::model::{
|
||||||
card::AddLabel,
|
Board, Card, NextcloudBoardId, NextcloudCardId, NextcloudHostname, NextcloudPassword,
|
||||||
model::{
|
NextcloudStackId, NextcloudUsername, Stack,
|
||||||
Board, Card, NextcloudBoardId, NextcloudCardId, NextcloudHostname, NextcloudPassword,
|
|
||||||
NextcloudStackId, NextcloudUsername, Stack,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
FullCtx,
|
FullCtx,
|
||||||
};
|
};
|
||||||
|
@ -78,11 +76,13 @@ impl<'ctx> DeckClient<'ctx> {
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn add_label_to_card(&self, add_label: &AddLabel) -> APIResult<()> {
|
pub(crate) async fn add_label_to_card(
|
||||||
let board_id = self.ctx.cfg.nextcloud.board_id;
|
&self,
|
||||||
let stack_id = add_label.stack_id;
|
board_id: NextcloudBoardId,
|
||||||
let card_id = add_label.card_id;
|
stack_id: NextcloudStackId,
|
||||||
let label_id = add_label.label_id;
|
card_id: NextcloudCardId,
|
||||||
|
label_id: NextcloudLabelId,
|
||||||
|
) -> APIResult<()> {
|
||||||
self.request_with_body(
|
self.request_with_body(
|
||||||
f!("boards/{board_id}/stacks/{stack_id}/cards/{card_id}/assignLabel"),
|
f!("boards/{board_id}/stacks/{stack_id}/cards/{card_id}/assignLabel"),
|
||||||
json!({
|
json!({
|
||||||
|
|
|
@ -59,6 +59,7 @@ async fn dump(
|
||||||
//when
|
//when
|
||||||
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel {
|
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel {
|
||||||
dump: true,
|
dump: true,
|
||||||
|
board_id: ctx.cfg.nextcloud.board_id.into(),
|
||||||
stack_id: stack_id.into(),
|
stack_id: stack_id.into(),
|
||||||
card_id: card_id.into(),
|
card_id: card_id.into(),
|
||||||
label_id: label_id.into(),
|
label_id: label_id.into(),
|
||||||
|
@ -87,6 +88,7 @@ async fn no_dump(
|
||||||
//when
|
//when
|
||||||
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel {
|
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::AddLabel {
|
||||||
dump: false,
|
dump: false,
|
||||||
|
board_id: ctx.cfg.nextcloud.board_id.into(),
|
||||||
stack_id: stack_id.into(),
|
stack_id: stack_id.into(),
|
||||||
card_id: card_id.into(),
|
card_id: card_id.into(),
|
||||||
label_id: label_id.into(),
|
label_id: label_id.into(),
|
||||||
|
|
|
@ -15,7 +15,6 @@ use crate::nextcloud::NextcloudCommand;
|
||||||
use crate::Command;
|
use crate::Command;
|
||||||
use crate::{
|
use crate::{
|
||||||
nextcloud::{
|
nextcloud::{
|
||||||
card::AddLabel,
|
|
||||||
model::{
|
model::{
|
||||||
Card, Label, NextcloudBoardId, NextcloudCardId, NextcloudCardTitle, NextcloudETag,
|
Card, Label, NextcloudBoardId, NextcloudCardId, NextcloudCardTitle, NextcloudETag,
|
||||||
NextcloudHostname, NextcloudLabelId, NextcloudOrder, NextcloudPassword,
|
NextcloudHostname, NextcloudLabelId, NextcloudOrder, NextcloudPassword,
|
||||||
|
|
Loading…
Reference in a new issue