79 lines
1.5 KiB
Rust
Raw Normal View History

2021-07-22 21:43:01 +08:00
use crate::{
entities::doc::parser::*,
errors::{ErrorBuilder, *},
};
use flowy_derive::ProtoBuf;
use std::convert::TryInto;
#[derive(ProtoBuf, Default)]
pub struct CreateDocRequest {
#[pb(index = 1)]
pub id: String,
2021-07-22 21:43:01 +08:00
#[pb(index = 2)]
pub name: String,
2021-07-23 08:14:45 +08:00
#[pb(index = 3)]
pub desc: String,
#[pb(index = 4)]
pub text: String,
2021-07-22 21:43:01 +08:00
}
pub struct CreateDocParams {
2021-07-23 08:14:45 +08:00
pub id: String,
2021-07-22 21:43:01 +08:00
pub name: String,
2021-07-23 08:14:45 +08:00
pub desc: String,
pub text: String,
2021-07-22 21:43:01 +08:00
}
impl TryInto<CreateDocParams> for CreateDocRequest {
2021-07-22 22:26:38 +08:00
type Error = EditorError;
2021-07-22 21:43:01 +08:00
fn try_into(self) -> Result<CreateDocParams, Self::Error> {
let name = DocName::parse(self.name)
.map_err(|e| {
ErrorBuilder::new(EditorErrorCode::DocNameInvalid)
.msg(e)
.build()
})?
.0;
2021-07-23 08:14:45 +08:00
let id = DocViewId::parse(self.id)
2021-07-22 21:43:01 +08:00
.map_err(|e| {
ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid)
.msg(e)
.build()
})?
.0;
2021-07-23 08:14:45 +08:00
Ok(CreateDocParams {
id,
name,
desc: self.desc,
text: self.text,
2021-07-23 08:14:45 +08:00
})
2021-07-22 21:43:01 +08:00
}
}
2021-07-22 22:26:38 +08:00
#[derive(ProtoBuf, Default, Debug)]
2021-07-24 14:05:49 +08:00
pub struct DocInfo {
2021-07-22 22:26:38 +08:00
#[pb(index = 1)]
pub id: String,
#[pb(index = 2)]
pub name: String,
#[pb(index = 3)]
2021-07-23 08:14:45 +08:00
pub desc: String,
#[pb(index = 4)]
pub path: String,
}
#[derive(ProtoBuf, Default, Debug)]
2021-07-24 14:05:49 +08:00
pub struct DocData {
#[pb(index = 1)]
pub text: String,
2021-07-22 22:26:38 +08:00
}