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

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

View file

@ -74,6 +74,12 @@ enum NextcloudCardCommand {
dump: bool,
stack_id: i64,
},
Get {
#[clap(long, action = clap::ArgAction::SetTrue)]
dump: bool,
stack_id: i64,
card_id: i64,
},
}
#[derive(Parser, Debug)]
@ -157,6 +163,11 @@ pub async fn run(ctx: Ctx) -> color_eyre::Result<()> {
dump,
stack_id,
})) => 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::{p, FullCtx};
use crate::{
nextcloud::model::{NextcloudCardId, NextcloudStackId},
p, FullCtx,
};
pub(crate) async fn list(
ctx: FullCtx,
@ -22,3 +24,22 @@ pub(crate) async fn list(
}
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

@ -141,4 +141,17 @@ impl<'ctx> DeckClient<'ctx> {
)
.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

@ -108,11 +108,9 @@ mod config {
}
mod commands {
use super::*;
mod board {
use super::*;
#[tokio::test]
@ -295,6 +293,7 @@ mod commands {
mod card {
use super::*;
use crate::nextcloud::model::{Label, NextcloudLabelId};
#[tokio::test]
async fn list() {
@ -341,6 +340,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
}