Skip to main content

wekan_cli/client/lists/
archival.rs

1use crate::client::{ClientError, WekanClient, transport::decode_success};
2use reqwest::header::ACCEPT;
3use secrecy::{ExposeSecret, SecretString};
4use serde::{Deserialize, Serialize};
5
6#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
7#[serde(deny_unknown_fields)]
8pub struct ListArchiveResponse {
9    #[serde(rename(deserialize = "_id", serialize = "list_id"))]
10    pub list_id: String,
11    pub archived: bool,
12}
13
14impl WekanClient {
15    pub async fn set_list_archived(
16        &self,
17        board_id: &str,
18        list_id: &str,
19        archived: bool,
20        token: &SecretString,
21    ) -> Result<ListArchiveResponse, ClientError> {
22        let mut endpoint = self.list_endpoint(board_id, Some(list_id))?;
23        endpoint
24            .path_segments_mut()
25            .expect("HTTP URL supports path segments")
26            .push(if archived { "archive" } else { "unarchive" });
27        let body = self
28            .execute_success_request(
29                self.http
30                    .post(endpoint)
31                    .header(ACCEPT, "application/json")
32                    .bearer_auth(token.expose_secret()),
33            )
34            .await?;
35        let response: ListArchiveResponse = decode_success(&body, "list archive/restore", true)?;
36        if response.list_id != list_id || response.archived != archived {
37            return Err(super::protocol_error(
38                "the list archive response did not match the requested list and state".to_owned(),
39            ));
40        }
41        Ok(response)
42    }
43}