Skip to main content

wekan_cli/command_result/
exports.rs

1use crate::client::exports::{ExportFormat, ExportMetadata, ExportTarget};
2use serde::Serialize;
3
4#[derive(Debug)]
5pub(crate) struct StagedExport(pub(crate) tempfile::NamedTempFile);
6impl PartialEq for StagedExport {
7    fn eq(&self, other: &Self) -> bool {
8        self.0.path() == other.0.path()
9    }
10}
11impl Eq for StagedExport {}
12
13#[derive(Debug, Eq, PartialEq, Serialize)]
14pub struct ExportSuccess {
15    pub resource: ExportResource,
16    pub board_id: String,
17    pub list_id: Option<String>,
18    pub card_id: Option<String>,
19    pub attachment_id: Option<String>,
20    pub format: ExportFormat,
21    pub destination: String,
22    pub bytes_written: u64,
23    pub file_saved: bool,
24    pub http_status: u16,
25    pub content_type: Option<String>,
26    #[serde(skip)]
27    pub(crate) staged: Option<StagedExport>,
28}
29#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
30#[serde(rename_all = "snake_case")]
31pub enum ExportResource {
32    Board,
33    Card,
34    Attachment,
35}
36impl ExportSuccess {
37    pub(crate) fn new(
38        target: ExportTarget,
39        format: ExportFormat,
40        destination: String,
41        response: ExportMetadata,
42    ) -> Self {
43        let (resource, board_id, list_id, card_id, attachment_id) = match target {
44            ExportTarget::Board { board_id } => (ExportResource::Board, board_id, None, None, None),
45            ExportTarget::Card {
46                board_id,
47                list_id,
48                card_id,
49            } => (
50                ExportResource::Card,
51                board_id,
52                Some(list_id),
53                Some(card_id),
54                None,
55            ),
56            ExportTarget::Attachment {
57                board_id,
58                attachment_id,
59            } => (
60                ExportResource::Attachment,
61                board_id,
62                None,
63                None,
64                Some(attachment_id),
65            ),
66        };
67        Self {
68            resource,
69            board_id,
70            list_id,
71            card_id,
72            attachment_id,
73            format,
74            destination,
75            bytes_written: response.bytes_written,
76            file_saved: false,
77            http_status: response.http_status,
78            content_type: response.content_type,
79            staged: None,
80        }
81    }
82}