confluence/
page.rs

1use chrono::offset::Utc;
2use chrono::DateTime;
3
4/// Page.
5#[derive(Debug)]
6pub struct Page {
7    /// The id of the page
8    pub id: i64,
9    /// The key of the space that this page belongs to
10    pub space: String,
11    /// The id of the parent page
12    pub parent_id: i64,
13    /// The title of the page
14    pub title: String,
15    /// The url to view this page online
16    pub url: String,
17    /// The version number of this page
18    pub version: i32,
19    /// The page content
20    pub content: String,
21    /// Timestamp page was created
22    pub created: DateTime<Utc>,
23    /// Username of the creator
24    pub creator: String,
25    /// Timestamp page was modified
26    pub modified: DateTime<Utc>,
27    /// Username of the page's last modifier
28    pub modifier: String,
29    /// Whether or not this page is the space's homepage
30    pub home_page: bool,
31    /// Status of the page (eg. current or deleted)
32    pub content_status: String,
33    /// Whether the page is current and not deleted
34    pub current: bool,
35}
36
37/// Page Summary.
38#[derive(Debug)]
39pub struct PageSummary {
40    /// The id of the page
41    pub id: i64,
42    /// The key of the space that this page belongs to
43    pub space: String,
44    /// The id of the parent page
45    pub parent_id: i64,
46    /// The title of the page
47    pub title: String,
48    /// The url to view this page online
49    pub url: String,
50}
51
52/// Page Object for creating a Page.
53#[derive(Debug)]
54pub struct UpdatePage {
55    /// The id of the page
56    pub id: Option<i64>,
57    /// The key of the space that this page belongs to
58    pub space: String,
59    /// The title of the page
60    pub title: String,
61    /// The page content
62    pub content: String,
63    /// The version number of this page
64    pub version: Option<i32>,
65    /// The id of the parent page
66    pub parent_id: Option<i64>,
67}
68
69/// Options for updating the page.
70#[derive(Debug)]
71pub struct PageUpdateOptions {
72    // Edit comment for the updated page
73    pub version_comment: Option<String>,
74    // Is this update a 'minor edit'? (default value: false)
75    pub minor_edit: bool,
76}
77
78impl PageUpdateOptions {
79    pub fn new_minor() -> PageUpdateOptions {
80        PageUpdateOptions {
81            version_comment: None,
82            minor_edit: true,
83        }
84    }
85
86    pub fn new_minor_with_comment<S: Into<String>>(comment: S) -> PageUpdateOptions {
87        PageUpdateOptions {
88            version_comment: Some(comment.into()),
89            minor_edit: true,
90        }
91    }
92}
93
94impl UpdatePage {
95    pub fn with_create_fields<S: Into<String>>(
96        parent_id: Option<i64>,
97        space: &str,
98        title: &str,
99        content: S,
100    ) -> UpdatePage {
101        UpdatePage {
102            id: None,
103            space: space.into(),
104            title: title.into(),
105            content: content.into(),
106            version: None,
107            parent_id,
108        }
109    }
110}
111
112impl From<Page> for UpdatePage {
113    fn from(other: Page) -> UpdatePage {
114        UpdatePage {
115            id: Some(other.id),
116            space: other.space,
117            title: other.title,
118            content: other.content,
119            version: Some(other.version),
120            parent_id: if other.parent_id == 0 {
121                None
122            } else {
123                Some(other.parent_id)
124            },
125        }
126    }
127}