82 lines
1.8 KiB
Rust
Raw Normal View History

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)]
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 {
#[pb(index = 1)]
2022-10-13 23:29:37 +08:00
pub doc_id: String,
#[pb(index = 2)]
pub data: Vec<u8>,
#[pb(index = 3)]
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 {
type Error = String;
2021-12-13 22:46:35 +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
}
2022-10-13 23:29:37 +08:00
Ok(DocumentPayloadPB {
doc_id: revision.object_id,
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)]
pub revisions: RepeatedRevision,
2021-09-14 16:22:44 +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
}
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() }
}
}