feat(nextcloud): add command 'nextcloud card create'
Some checks failed
Test / build (map[name:nightly]) (push) Successful in 1m46s
Test / build (map[name:stable]) (push) Successful in 2m4s
Release Please / Release-plz (push) Failing after 16s

This commit is contained in:
Paul Campbell 2024-12-08 14:39:03 +00:00
parent 8df5e13837
commit b6831e6de0
4 changed files with 86 additions and 18 deletions

View file

@ -82,6 +82,15 @@ enum NextcloudCardCommand {
stack_id: i64,
card_id: i64,
},
Create {
#[clap(long, action = clap::ArgAction::SetTrue)]
dump: bool,
stack_id: i64,
#[clap(long)]
title: String,
#[clap(long)]
description: Option<String>,
},
}
#[derive(Parser, Debug)]
@ -188,6 +197,23 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> {
stack_id,
card_id,
} => nextcloud::card::get(ctx, dump, stack_id.into(), card_id.into()).await,
NextcloudCardCommand::Create {
dump,
stack_id,
title,
description,
} => {
nextcloud::card::create(
ctx,
nextcloud::card::Create {
dump,
stack_id,
title,
description,
},
)
.await
}
},
},
}

View file

@ -43,3 +43,21 @@ pub(crate) async fn get(
}
Ok(())
}
pub(crate) struct Create {
pub dump: bool,
pub stack_id: i64,
pub title: String,
pub description: Option<String>,
}
pub(crate) async fn create(ctx: FullCtx, create: Create) -> color_eyre::Result<()> {
let dc = ctx.deck_client();
let apiresult = dc.create_card(&create).await;
if create.dump {
p!(ctx.prt, "{}", apiresult.text);
} else {
let card = apiresult.result?;
p!(ctx.prt, "{}:{}", card.id, card.title);
}
Ok(())
}

View file

@ -2,14 +2,12 @@
use bytes::Bytes;
use kxio::net::{Net, ReqBuilder};
use crate::{
api_result::APIResult,
f,
nextcloud::model::{
use crate::{api_result::APIResult, f, FullCtx};
use card::Create;
use model::{
Board, Card, NextcloudBoardId, NextcloudHostname, NextcloudPassword, NextcloudStackId,
NextcloudUsername, Stack,
},
FullCtx,
};
pub mod board;
@ -26,6 +24,8 @@ pub(crate) struct DeckClient<'ctx> {
username: &'ctx NextcloudUsername,
password: &'ctx NextcloudPassword,
}
// Uses the API described here: https://deck.readthedocs.io/en/stable/API/#cards
impl<'ctx> DeckClient<'ctx> {
pub fn new(ctx: &'ctx FullCtx) -> Self {
Self {
@ -118,23 +118,20 @@ impl<'ctx> DeckClient<'ctx> {
.await
}
pub async fn create_card(
&self,
board_id: i64,
stack_id: i64,
title: &str,
description: Option<&str>,
) -> APIResult<Card> {
pub(crate) async fn create_card(&self, create: &Create) -> APIResult<Card> {
let mut body = serde_json::json!({
"title": title,
"title": create.title,
});
if let Some(desc) = description {
if let Some(desc) = &create.description {
body["description"] = serde_json::Value::String(desc.to_string());
}
self.request_with_body(
format!("boards/{}/stacks/{}/cards", board_id, stack_id),
format!(
"boards/{}/stacks/{}/cards",
self.ctx.cfg.nextcloud.board_id, create.stack_id
),
body.to_string(),
|net, url| net.post(url),
)

View file

@ -0,0 +1,27 @@
{
"id": 331,
"title": "my new card",
"description": "my new description",
"descriptionPrev": null,
"stackId": 1,
"type": "plain",
"lastModified": 1733669509,
"lastEditor": null,
"createdAt": 1733669509,
"labels": null,
"assignedUsers": null,
"attachments": null,
"attachmentCount": null,
"owner": "pcampbell",
"order": 999,
"archived": false,
"done": null,
"duedate": null,
"notified": false,
"deletedAt": 0,
"commentsUnread": 0,
"commentsCount": 0,
"relatedStack": null,
"relatedBoard": null,
"ETag": "a3aee71091453c0e2055e4f2c31b611f"
}