atlas_confluence/
models.rs

1use serde::{Deserialize, Serialize};
2
3#[derive(Serialize, Deserialize, Clone, Debug)]
4pub struct Space {
5    pub id: u64,
6    pub key: String,
7    pub name: String,
8    #[serde(rename = "_expandable")]
9    pub expandable: SpaceExpandable,
10}
11
12#[derive(Serialize, Deserialize, Clone, Debug)]
13pub struct SpaceExpandable {
14    pub homepage: Option<String>,
15}
16
17#[derive(Serialize, Deserialize, Clone, Debug)]
18pub struct PageChildren {
19    pub page: PaginatedResponse<ChildPage>,
20    #[serde(rename = "_links")]
21    pub links: Links,
22}
23
24#[derive(Serialize, Deserialize, Clone, Debug)]
25pub struct Page {
26    pub id: String,
27    pub title: String,
28    pub status: String,
29    pub space: Space,
30    pub version: Version,
31    pub body: Option<Body>,
32    #[serde(rename = "_links")]
33    pub links: Links,
34    pub children: Option<PageChildren>,
35}
36
37#[derive(Serialize, Deserialize, Clone, Debug)]
38pub struct ChildPage {
39    pub id: String,
40    pub title: String,
41    pub status: String,
42    #[serde(rename = "_links")]
43    pub links: Links,
44}
45
46#[derive(Serialize, Deserialize, Clone, Debug)]
47pub struct Version {
48    pub number: u64,
49}
50
51#[derive(Serialize, Deserialize, Clone, Debug)]
52pub struct Body {
53    pub view: Option<BodyView>,
54}
55
56#[derive(Serialize, Deserialize, Clone, Debug)]
57pub struct BodyView {
58    pub value: String,
59}
60
61#[derive(Serialize, Deserialize, Clone, Debug)]
62pub struct SpacesResult {
63    pub results: Vec<Space>,
64}
65
66#[derive(Serialize, Deserialize, Clone, Debug)]
67pub struct Links {
68    pub next: Option<String>,
69    pub prev: Option<String>,
70    pub base: Option<String>,
71    pub webui: Option<String>,
72    #[serde(rename = "self")]
73    pub _self: String,
74}
75
76#[derive(Serialize, Deserialize, Clone, Debug)]
77pub struct PaginatedResponse<T> {
78    pub size: u64,
79    pub limit: u64,
80    pub start: u64,
81    #[serde(rename = "_links")]
82    pub links: Links,
83    pub results: Vec<T>,
84}
85
86#[derive(Serialize, Deserialize, Clone, Debug)]
87pub struct SpaceContentResult {
88    pub page: PaginatedResponse<Page>,
89}
90
91#[derive(Serialize, Deserialize, Clone, Debug)]
92pub struct PostPage {
93    pub id: Option<String>,
94    #[serde(rename = "type")]
95    pub t: String,
96    pub title: String,
97    pub ancestors: Option<Vec<PostAncestor>>,
98    pub space: PostSpace,
99    pub body: Option<PostBody>,
100    pub version: Option<PostVersion>,
101}
102impl PostPage {
103    pub fn new_new_page(
104        title: String,
105        ancestor: Option<u64>,
106        space_key: String,
107        body: Option<String>,
108    ) -> Self {
109        PostPage {
110            id: None,
111            t: "page".to_string(),
112            title,
113            ancestors: ancestor.map(|ancestor_id| {
114                vec![PostAncestor {
115                    id: format!("{ancestor_id}"),
116                }]
117            }),
118            space: PostSpace { key: space_key },
119            body: body.map(PostBody::new),
120            version: None,
121        }
122    }
123    pub fn new_update_page(
124        id: u64,
125        title: String,
126        space_key: String,
127        body: Option<String>,
128        new_version: u64,
129    ) -> Self {
130        PostPage {
131            id: Some(format!("{id}")),
132            t: "page".to_string(),
133            title,
134            ancestors: None,
135            space: PostSpace { key: space_key },
136            body: body.map(PostBody::new),
137            version: Some(PostVersion {
138                number: new_version,
139            }),
140        }
141    }
142}
143
144#[derive(Serialize, Deserialize, Clone, Debug)]
145pub struct PostAncestor {
146    pub id: String,
147}
148
149#[derive(Serialize, Deserialize, Clone, Debug)]
150pub struct PostSpace {
151    pub key: String,
152}
153
154#[derive(Serialize, Deserialize, Clone, Debug)]
155pub struct PostBody {
156    pub storage: PostStorage,
157}
158impl PostBody {
159    pub fn new(value: String) -> Self {
160        PostBody {
161            storage: PostStorage {
162                value,
163                representation: "storage".to_string(),
164            },
165        }
166    }
167}
168
169#[derive(Serialize, Deserialize, Clone, Debug)]
170pub struct PostStorage {
171    pub value: String,
172    pub representation: String,
173}
174
175#[derive(Serialize, Deserialize, Clone, Debug)]
176pub struct PostVersion {
177    pub number: u64,
178}