lib_client_confluence/
types.rs

1use serde::{Deserialize, Serialize};
2
3/// Page in Confluence.
4#[derive(Debug, Clone, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct Page {
7    pub id: String,
8    pub title: String,
9    #[serde(rename = "type")]
10    pub content_type: String,
11    pub status: String,
12    pub space: Option<SpaceRef>,
13    pub body: Option<Body>,
14    pub version: Option<Version>,
15    #[serde(rename = "_links")]
16    pub links: Option<Links>,
17}
18
19/// Space reference.
20#[derive(Debug, Clone, Deserialize)]
21pub struct SpaceRef {
22    pub id: Option<String>,
23    pub key: String,
24    pub name: Option<String>,
25}
26
27/// Body content.
28#[derive(Debug, Clone, Serialize, Deserialize)]
29pub struct Body {
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub storage: Option<Storage>,
32    #[serde(skip_serializing_if = "Option::is_none")]
33    pub view: Option<Storage>,
34}
35
36/// Storage format content.
37#[derive(Debug, Clone, Serialize, Deserialize)]
38pub struct Storage {
39    pub value: String,
40    pub representation: String,
41}
42
43impl Storage {
44    pub fn storage(value: impl Into<String>) -> Self {
45        Self {
46            value: value.into(),
47            representation: "storage".to_string(),
48        }
49    }
50}
51
52/// Version info.
53#[derive(Debug, Clone, Serialize, Deserialize)]
54pub struct Version {
55    pub number: u32,
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub message: Option<String>,
58}
59
60/// Links.
61#[derive(Debug, Clone, Deserialize)]
62pub struct Links {
63    #[serde(rename = "webui")]
64    pub web_ui: Option<String>,
65    #[serde(rename = "self")]
66    pub self_url: Option<String>,
67}
68
69/// Space in Confluence.
70#[derive(Debug, Clone, Deserialize)]
71#[serde(rename_all = "camelCase")]
72pub struct Space {
73    pub id: String,
74    pub key: String,
75    pub name: String,
76    #[serde(rename = "type")]
77    pub space_type: String,
78    pub status: String,
79    #[serde(rename = "_links")]
80    pub links: Option<Links>,
81}
82
83/// Content search result.
84#[derive(Debug, Clone, Deserialize)]
85pub struct SearchResult {
86    pub results: Vec<Page>,
87    pub start: u32,
88    pub limit: u32,
89    pub size: u32,
90    #[serde(rename = "_links")]
91    pub links: Option<SearchLinks>,
92}
93
94#[derive(Debug, Clone, Deserialize)]
95pub struct SearchLinks {
96    pub next: Option<String>,
97}
98
99/// Spaces list result.
100#[derive(Debug, Clone, Deserialize)]
101pub struct SpacesResult {
102    pub results: Vec<Space>,
103    pub start: u32,
104    pub limit: u32,
105    pub size: u32,
106}
107
108/// Children result.
109#[derive(Debug, Clone, Deserialize)]
110pub struct ChildrenResult {
111    pub page: Option<PageChildren>,
112}
113
114#[derive(Debug, Clone, Deserialize)]
115pub struct PageChildren {
116    pub results: Vec<Page>,
117    pub start: u32,
118    pub limit: u32,
119    pub size: u32,
120}
121
122/// Create page input.
123#[derive(Debug, Clone, Serialize)]
124#[serde(rename_all = "camelCase")]
125pub struct CreatePageInput {
126    #[serde(rename = "type")]
127    pub content_type: String,
128    pub title: String,
129    pub space: SpaceKey,
130    pub body: Body,
131    #[serde(skip_serializing_if = "Option::is_none")]
132    pub ancestors: Option<Vec<Ancestor>>,
133}
134
135#[derive(Debug, Clone, Serialize)]
136pub struct SpaceKey {
137    pub key: String,
138}
139
140#[derive(Debug, Clone, Serialize)]
141pub struct Ancestor {
142    pub id: String,
143}
144
145impl CreatePageInput {
146    pub fn new(space_key: impl Into<String>, title: impl Into<String>, body: impl Into<String>) -> Self {
147        Self {
148            content_type: "page".to_string(),
149            title: title.into(),
150            space: SpaceKey { key: space_key.into() },
151            body: Body {
152                storage: Some(Storage::storage(body)),
153                view: None,
154            },
155            ancestors: None,
156        }
157    }
158
159    pub fn parent(mut self, parent_id: impl Into<String>) -> Self {
160        self.ancestors = Some(vec![Ancestor { id: parent_id.into() }]);
161        self
162    }
163}
164
165/// Update page input.
166#[derive(Debug, Clone, Serialize)]
167#[serde(rename_all = "camelCase")]
168pub struct UpdatePageInput {
169    pub version: Version,
170    pub title: String,
171    #[serde(rename = "type")]
172    pub content_type: String,
173    pub body: Body,
174}
175
176impl UpdatePageInput {
177    pub fn new(
178        version: u32,
179        title: impl Into<String>,
180        body: impl Into<String>,
181    ) -> Self {
182        Self {
183            version: Version {
184                number: version,
185                message: None,
186            },
187            title: title.into(),
188            content_type: "page".to_string(),
189            body: Body {
190                storage: Some(Storage::storage(body)),
191                view: None,
192            },
193        }
194    }
195
196    pub fn message(mut self, message: impl Into<String>) -> Self {
197        self.version.message = Some(message.into());
198        self
199    }
200}
201
202/// Attachment.
203#[derive(Debug, Clone, Deserialize)]
204#[serde(rename_all = "camelCase")]
205pub struct Attachment {
206    pub id: String,
207    pub title: String,
208    pub media_type: String,
209    pub file_size: u64,
210    #[serde(rename = "_links")]
211    pub links: Option<AttachmentLinks>,
212}
213
214#[derive(Debug, Clone, Deserialize)]
215pub struct AttachmentLinks {
216    pub download: Option<String>,
217    #[serde(rename = "webui")]
218    pub web_ui: Option<String>,
219}
220
221/// Attachments result.
222#[derive(Debug, Clone, Deserialize)]
223pub struct AttachmentsResult {
224    pub results: Vec<Attachment>,
225    pub start: u32,
226    pub limit: u32,
227    pub size: u32,
228}