wekan_cli/command_result/
exports.rs1use 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: Option<String>,
17 pub chart_key: Option<String>,
18 pub list_id: Option<String>,
19 pub card_id: Option<String>,
20 pub attachment_id: Option<String>,
21 pub format: ExportFormat,
22 pub destination: String,
23 pub bytes_written: u64,
24 pub file_saved: bool,
25 pub http_status: u16,
26 pub content_type: Option<String>,
27 #[serde(skip)]
28 pub(crate) staged: Option<StagedExport>,
29}
30#[derive(Clone, Copy, Debug, Eq, PartialEq, Serialize)]
31#[serde(rename_all = "snake_case")]
32pub enum ExportResource {
33 Board,
34 Boards,
35 Chart,
36 Card,
37 Attachment,
38}
39impl ExportSuccess {
40 pub(crate) fn new(
41 target: ExportTarget,
42 format: ExportFormat,
43 destination: String,
44 response: ExportMetadata,
45 ) -> Self {
46 let (resource, board_id, list_id, card_id, attachment_id, chart_key) = match target {
47 ExportTarget::AllBoards => (ExportResource::Boards, None, None, None, None, None),
48 ExportTarget::Chart {
49 board_id,
50 chart_key,
51 } => (
52 ExportResource::Chart,
53 Some(board_id),
54 None,
55 None,
56 None,
57 Some(chart_key),
58 ),
59 ExportTarget::Board { board_id } => (
60 ExportResource::Board,
61 Some(board_id),
62 None,
63 None,
64 None,
65 None,
66 ),
67 ExportTarget::Card {
68 board_id,
69 list_id,
70 card_id,
71 } => (
72 ExportResource::Card,
73 Some(board_id),
74 Some(list_id),
75 Some(card_id),
76 None,
77 None,
78 ),
79 ExportTarget::Attachment {
80 board_id,
81 attachment_id,
82 } => (
83 ExportResource::Attachment,
84 Some(board_id),
85 None,
86 None,
87 Some(attachment_id),
88 None,
89 ),
90 };
91 Self {
92 resource,
93 board_id,
94 chart_key,
95 list_id,
96 card_id,
97 attachment_id,
98 format,
99 destination,
100 bytes_written: response.bytes_written,
101 file_saved: false,
102 http_status: response.http_status,
103 content_type: response.content_type,
104 staged: None,
105 }
106 }
107}