mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-11-19 20:07:49 +00:00
45 lines
1.0 KiB
Rust
45 lines
1.0 KiB
Rust
|
|
use crate::{
|
||
|
|
entities::doc::parser::*,
|
||
|
|
errors::{ErrorBuilder, *},
|
||
|
|
};
|
||
|
|
use flowy_derive::ProtoBuf;
|
||
|
|
use std::convert::TryInto;
|
||
|
|
|
||
|
|
#[derive(ProtoBuf, Default)]
|
||
|
|
pub struct CreateDocRequest {
|
||
|
|
#[pb(index = 1)]
|
||
|
|
view_id: String,
|
||
|
|
|
||
|
|
#[pb(index = 2)]
|
||
|
|
pub name: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
pub struct CreateDocParams {
|
||
|
|
pub view_id: String,
|
||
|
|
pub name: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
impl TryInto<CreateDocParams> for CreateDocRequest {
|
||
|
|
type Error = WorkspaceError;
|
||
|
|
|
||
|
|
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;
|
||
|
|
|
||
|
|
let view_id = DocViewId::parse(self.view_id)
|
||
|
|
.map_err(|e| {
|
||
|
|
ErrorBuilder::new(EditorErrorCode::DocViewIdInvalid)
|
||
|
|
.msg(e)
|
||
|
|
.build()
|
||
|
|
})?
|
||
|
|
.0;
|
||
|
|
|
||
|
|
Ok(CreateDocParams { view_id, name })
|
||
|
|
}
|
||
|
|
}
|