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