feat(nextcloud): add command 'nextcloud card get'

This commit is contained in:
Paul Campbell 2024-12-07 09:56:40 +00:00
parent de9a378b3e
commit 29580088e6
5 changed files with 142 additions and 4 deletions

View file

@ -74,6 +74,12 @@ enum NextcloudCardCommand {
dump: bool, dump: bool,
stack_id: i64, stack_id: i64,
}, },
Get {
#[clap(long, action = clap::ArgAction::SetTrue)]
dump: bool,
stack_id: i64,
card_id: i64,
},
} }
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
@ -157,6 +163,11 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> {
dump, dump,
stack_id, stack_id,
})) => nextcloud::card::list(ctx, dump, stack_id.into()).await, })) => nextcloud::card::list(ctx, dump, stack_id.into()).await,
Command::Nextcloud(NextcloudCommand::Card(NextcloudCardCommand::Get {
dump,
stack_id,
card_id,
})) => nextcloud::card::get(ctx, dump, stack_id.into(), card_id.into()).await,
} }
} }
} }

View file

@ -1,6 +1,8 @@
// //
use crate::nextcloud::model::NextcloudStackId; use crate::{
use crate::{p, FullCtx}; nextcloud::model::{NextcloudCardId, NextcloudStackId},
p, FullCtx,
};
pub(crate) async fn list( pub(crate) async fn list(
ctx: FullCtx, ctx: FullCtx,
@ -22,3 +24,22 @@ pub(crate) async fn list(
} }
Ok(()) Ok(())
} }
pub(crate) async fn get(
ctx: FullCtx,
dump: bool,
stack_id: NextcloudStackId,
card_id: NextcloudCardId,
) -> color_eyre::Result<()> {
let api_result = ctx
.deck_client()
.get_card(ctx.cfg.nextcloud.board_id, stack_id, card_id)
.await;
if dump {
p!(ctx.prt, "{}", api_result.text);
} else {
let card = api_result.result?;
p!(ctx.prt, "{}:{}", card.id, card.title);
}
Ok(())
}

View file

@ -140,4 +140,17 @@ impl<'ctx> DeckClient<'ctx> {
) )
.await .await
} }
async fn get_card(
&self,
board_id: NextcloudBoardId,
stack_id: NextcloudStackId,
card_id: model::NextcloudCardId,
) -> APIResult<Card> {
self.request(
f!("boards/{board_id}/stacks/{stack_id}/cards/{card_id}"),
|net, url| net.get(url),
)
.await
}
} }

View file

@ -100,11 +100,9 @@ mod config {
} }
mod commands { mod commands {
use super::*; use super::*;
mod board { mod board {
use super::*; use super::*;
#[tokio::test] #[tokio::test]
@ -287,6 +285,7 @@ mod commands {
mod card { mod card {
use super::*; use super::*;
use crate::nextcloud::model::{Label, NextcloudLabelId};
#[tokio::test] #[tokio::test]
async fn list() { async fn list() {
@ -333,6 +332,49 @@ mod commands {
} }
); );
} }
#[tokio::test]
async fn get() {
//given
let mock_net = kxio::net::mock();
mock_net
.on()
.get("https://host-name/index.php/apps/deck/api/v1.0/boards/2/stacks/1/cards/321")
.basic_auth("username", Some("password"))
.respond(StatusCode::OK)
.body(include_str!("../tests/responses/nextcloud-card-get.json"))
.expect("mock request");
let fs = given::a_filesystem();
let ctx = given::a_full_context(mock_net, fs);
let deck_client = DeckClient::new(&ctx);
//when
let result = deck_client
.get_card(ctx.cfg.nextcloud.board_id, 1.into(), 321.into())
.await
.result
.expect("get stacks");
assert_eq!(
result,
Card {
id: NextcloudCardId::new(321),
title: NextcloudCardTitle::new("Breakfast: Cereal"),
description: Some(s!("")),
stack_id: NextcloudStackId::new(1),
order: NextcloudOrder::new(1),
archived: false,
due_date: None,
labels: Some(vec![Label {
id: NextcloudLabelId::new(1),
title: s!("Finished"),
color: s!("31CC7C")
}])
}
);
}
} }
} }

View file

@ -0,0 +1,51 @@
{
"id": 321,
"title": "Breakfast: Cereal",
"description": "",
"stackId": 1,
"type": "plain",
"lastModified": 1733515897,
"lastEditor": null,
"createdAt": 1733043461,
"labels": [
{
"id": 1,
"title": "Finished",
"color": "31CC7C",
"boardId": 1,
"cardId": 321,
"lastModified": 1670965629,
"ETag": "983f87848dc9c18d0aee63e7ee0fc83f"
}
],
"assignedUsers": [
{
"id": 24,
"participant": {
"primaryKey": "pcampbell",
"uid": "pcampbell",
"displayname": "Paul Campbell",
"type": 0
},
"cardId": 321,
"type": 0
}
],
"attachments": [],
"attachmentCount": 0,
"owner": {
"primaryKey": "pcampbell",
"uid": "pcampbell",
"displayname": "Paul Campbell",
"type": 0
},
"order": 1,
"archived": false,
"done": null,
"duedate": null,
"deletedAt": 0,
"commentsUnread": 0,
"commentsCount": 0,
"ETag": "bf59162abcbc193b94349985122d7009",
"overdue": 0
}