2023-01-30 11:11:19 +08:00
|
|
|
use revision_model::Revision;
|
2022-12-30 11:16:47 +08:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-07-22 21:43:01 +08:00
|
|
|
|
2022-12-30 11:16:47 +08:00
|
|
|
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
|
2022-10-13 23:29:37 +08:00
|
|
|
pub struct CreateDocumentParams {
|
2023-02-13 09:29:49 +08:00
|
|
|
pub doc_id: String,
|
|
|
|
|
pub revisions: Vec<Revision>,
|
2021-09-11 14:26:30 +08:00
|
|
|
}
|
|
|
|
|
|
2022-12-30 11:16:47 +08:00
|
|
|
#[derive(Serialize, Deserialize, Default, Debug, Clone, Eq, PartialEq)]
|
2023-01-30 11:11:19 +08:00
|
|
|
pub struct DocumentInfo {
|
2023-02-13 09:29:49 +08:00
|
|
|
pub doc_id: String,
|
|
|
|
|
pub data: Vec<u8>,
|
|
|
|
|
pub rev_id: i64,
|
|
|
|
|
pub base_rev_id: i64,
|
2021-10-06 15:23:38 +08:00
|
|
|
}
|
|
|
|
|
|
2023-01-30 11:11:19 +08:00
|
|
|
impl std::convert::TryFrom<Revision> for DocumentInfo {
|
2023-02-13 09:29:49 +08:00
|
|
|
type Error = String;
|
2021-12-13 22:46:35 +08:00
|
|
|
|
2023-02-13 09:29:49 +08:00
|
|
|
fn try_from(revision: Revision) -> Result<Self, Self::Error> {
|
|
|
|
|
if !revision.is_initial() {
|
|
|
|
|
return Err("Revision's rev_id should be 0 when creating the document".to_string());
|
2021-12-13 22:46:35 +08:00
|
|
|
}
|
2023-02-13 09:29:49 +08:00
|
|
|
|
|
|
|
|
Ok(DocumentInfo {
|
|
|
|
|
doc_id: revision.object_id,
|
|
|
|
|
data: revision.bytes,
|
|
|
|
|
rev_id: revision.rev_id,
|
|
|
|
|
base_rev_id: revision.base_rev_id,
|
|
|
|
|
})
|
|
|
|
|
}
|
2021-12-13 22:46:35 +08:00
|
|
|
}
|
|
|
|
|
|
2022-12-30 11:16:47 +08:00
|
|
|
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
|
2022-10-13 23:29:37 +08:00
|
|
|
pub struct ResetDocumentParams {
|
2023-02-13 09:29:49 +08:00
|
|
|
pub doc_id: String,
|
|
|
|
|
pub revisions: Vec<Revision>,
|
2021-09-14 16:22:44 +08:00
|
|
|
}
|
|
|
|
|
|
2022-12-30 11:16:47 +08:00
|
|
|
#[derive(Serialize, Deserialize, Default, Debug, Clone)]
|
|
|
|
|
pub struct DocumentId {
|
2023-02-13 09:29:49 +08:00
|
|
|
pub value: String,
|
2021-07-22 22:26:38 +08:00
|
|
|
}
|
2022-12-30 11:16:47 +08:00
|
|
|
impl AsRef<str> for DocumentId {
|
2023-02-13 09:29:49 +08:00
|
|
|
fn as_ref(&self) -> &str {
|
|
|
|
|
&self.value
|
|
|
|
|
}
|
2022-03-06 21:22:42 +08:00
|
|
|
}
|
2021-10-15 13:42:52 +08:00
|
|
|
|
2022-12-30 11:16:47 +08:00
|
|
|
impl std::convert::From<String> for DocumentId {
|
2023-02-13 09:29:49 +08:00
|
|
|
fn from(value: String) -> Self {
|
|
|
|
|
DocumentId { value }
|
|
|
|
|
}
|
2021-10-15 13:42:52 +08:00
|
|
|
}
|
2021-10-19 13:04:09 +08:00
|
|
|
|
2022-12-30 11:16:47 +08:00
|
|
|
impl std::convert::From<DocumentId> for String {
|
2023-02-13 09:29:49 +08:00
|
|
|
fn from(block_id: DocumentId) -> Self {
|
|
|
|
|
block_id.value
|
|
|
|
|
}
|
2022-03-06 21:22:42 +08:00
|
|
|
}
|
|
|
|
|
|
2022-12-30 11:16:47 +08:00
|
|
|
impl std::convert::From<&String> for DocumentId {
|
2023-02-13 09:29:49 +08:00
|
|
|
fn from(s: &String) -> Self {
|
|
|
|
|
DocumentId {
|
|
|
|
|
value: s.to_owned(),
|
2021-10-19 13:04:09 +08:00
|
|
|
}
|
2023-02-13 09:29:49 +08:00
|
|
|
}
|
2021-10-19 13:04:09 +08:00
|
|
|
}
|