use chrono::offset::Utc;
use chrono::DateTime;
#[derive(Debug)]
pub struct Page {
pub id: i64,
pub space: String,
pub parent_id: i64,
pub title: String,
pub url: String,
pub version: i32,
pub content: String,
pub created: DateTime<Utc>,
pub creator: String,
pub modified: DateTime<Utc>,
pub modifier: String,
pub home_page: bool,
pub content_status: String,
pub current: bool,
}
#[derive(Debug)]
pub struct PageSummary {
pub id: i64,
pub space: String,
pub parent_id: i64,
pub title: String,
pub url: String,
}
#[derive(Debug)]
pub struct UpdatePage {
pub id: Option<i64>,
pub space: String,
pub title: String,
pub content: String,
pub version: Option<i32>,
pub parent_id: Option<i64>,
}
#[derive(Debug)]
pub struct PageUpdateOptions {
pub version_comment: Option<String>,
pub minor_edit: bool,
}
impl PageUpdateOptions {
pub fn new_minor() -> PageUpdateOptions {
PageUpdateOptions {
version_comment: None,
minor_edit: true,
}
}
pub fn new_minor_with_comment<S: Into<String>>(comment: S) -> PageUpdateOptions {
PageUpdateOptions {
version_comment: Some(comment.into()),
minor_edit: true,
}
}
}
impl UpdatePage {
pub fn with_create_fields<S: Into<String>>(
parent_id: Option<i64>,
space: &str,
title: &str,
content: S,
) -> UpdatePage {
UpdatePage {
id: None,
space: space.into(),
title: title.into(),
content: content.into(),
version: None,
parent_id,
}
}
}
impl From<Page> for UpdatePage {
fn from(other: Page) -> UpdatePage {
UpdatePage {
id: Some(other.id),
space: other.space,
title: other.title,
content: other.content,
version: Some(other.version),
parent_id: if other.parent_id == 0 {
None
} else {
Some(other.parent_id)
},
}
}
}