wekan_cli/client/cards/
copy.rs1use super::{ClientError, IdResponse, WekanClient, require_non_empty};
2use crate::client::transport::decode_success;
3use reqwest::header::ACCEPT;
4use secrecy::{ExposeSecret, SecretString};
5use serde::{Deserialize, Serialize};
6use serde_json::Number;
7
8#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
10#[serde(untagged)]
11pub enum CardCopyPosition {
12 Number(Number),
13 Text(String),
14 Null,
15}
16
17#[derive(Clone, Debug, Eq, PartialEq, Serialize)]
18pub struct CopyCardRequest {
19 #[serde(rename = "toBoardId", skip_serializing_if = "Option::is_none")]
20 pub target_board_id: Option<String>,
21 #[serde(rename = "toSwimlaneId")]
22 pub target_swimlane_id: String,
23 #[serde(rename = "toListId", skip_serializing_if = "Option::is_none")]
24 pub target_list_id: Option<String>,
25 #[serde(skip_serializing_if = "Option::is_none")]
26 pub position: Option<CardCopyPosition>,
27}
28impl WekanClient {
29 pub async fn copy_card(
30 &self,
31 board_id: &str,
32 list_id: &str,
33 card_id: &str,
34 request: &CopyCardRequest,
35 token: &SecretString,
36 ) -> Result<String, ClientError> {
37 let mut endpoint = self.card_endpoint(board_id, list_id, Some(card_id))?;
38 endpoint
39 .path_segments_mut()
40 .expect("HTTP endpoint")
41 .push("copy");
42 let body = self
43 .execute_success_request(
44 self.http
45 .post(endpoint)
46 .header(ACCEPT, "application/json")
47 .bearer_auth(token.expose_secret())
48 .json(request),
49 )
50 .await?;
51 let response: IdResponse = decode_success(&body, "card copy", true)?;
52 require_non_empty(&response.id, "card copy", "card id")?;
53 Ok(response.id)
54 }
55}