diff --git a/src/nextcloud/board.rs b/src/nextcloud/board.rs index c874315..6dfc260 100644 --- a/src/nextcloud/board.rs +++ b/src/nextcloud/board.rs @@ -2,7 +2,7 @@ use clap::Parser; use crate::execute::Execute; -use crate::nextcloud::model::NextcloudBoardId; +use crate::nextcloud::model::{NextcloudBoardId, NextcloudLabelColour, NextcloudLabelTitle}; use crate::{p, FullCtx}; #[derive(Parser, Debug)] @@ -17,6 +17,13 @@ pub enum NextcloudBoardCommand { dump: bool, board_id: i64, }, + CreateLabel { + #[clap(long, action = clap::ArgAction::SetTrue)] + dump: bool, + board_id: i64, + title: String, + colour: String, + }, } impl Execute for NextcloudBoardCommand { @@ -61,6 +68,35 @@ impl Execute for NextcloudBoardCommand { } Ok(()) } + Self::CreateLabel { + dump, + board_id, + title, + colour, + } => { + let api_result = ctx + .deck_client() + .create_label( + NextcloudBoardId::new(*board_id), + &NextcloudLabelTitle::new(title), + &NextcloudLabelColour::new(colour), + ) + .await; + if *dump { + p!(ctx.prt, "{}", api_result.text); + } else { + let label = api_result.result?; + p!( + ctx.prt, + "{}:{}:{}:{}", + board_id, + label.id, + label.title, + label.color + ); + } + Ok(()) + } } } } diff --git a/src/nextcloud/client.rs b/src/nextcloud/client.rs index fdbea72..688ee62 100644 --- a/src/nextcloud/client.rs +++ b/src/nextcloud/client.rs @@ -8,7 +8,10 @@ use reqwest::multipart; use serde::de::DeserializeOwned; use serde_json::json; -use crate::nextcloud::model::{NextcloudCardDescription, NextcloudCardTitle, NextcloudStackTitle}; +use crate::nextcloud::model::{ + Label, NextcloudCardDescription, NextcloudCardTitle, NextcloudLabelColour, NextcloudLabelTitle, + NextcloudStackTitle, +}; use crate::{ api_result::APIResult, f, @@ -181,6 +184,24 @@ impl<'ctx> DeckClient<'ctx> { .await } + pub(crate) async fn create_label( + &self, + board_id: NextcloudBoardId, + name: &NextcloudLabelTitle, + colour: &NextcloudLabelColour, + ) -> APIResult