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)]
|
2021-07-23 08:14:45 +08:00
|
|
|
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,
|
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,
|
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,
|
|
|
|
|
})
|
2021-07-22 21:43:01 +08:00
|
|
|
}
|
|
|
|
|
}
|
2021-07-22 22:26:38 +08:00
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Default, Debug)]
|
|
|
|
|
pub struct Doc {
|
|
|
|
|
#[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,
|
|
|
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
|
pub content: String,
|
2021-07-22 22:26:38 +08:00
|
|
|
}
|