46 lines
934 B
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 data: String,
2021-07-22 21:43:01 +08:00
}
#[derive(ProtoBuf, Default, Debug, Clone)]
2021-07-22 21:43:01 +08:00
pub struct CreateDocParams {
#[pb(index = 1)]
2021-07-23 08:14:45 +08:00
pub id: String,
#[pb(index = 2)]
pub data: String,
2021-07-22 21:43:01 +08:00
}
impl TryInto<CreateDocParams> for CreateDocRequest {
2021-07-31 10:50:56 +08:00
type Error = DocError;
2021-07-22 21:43:01 +08:00
fn try_into(self) -> Result<CreateDocParams, Self::Error> {
2021-09-09 17:34:01 +08:00
let id = DocId::parse(self.id)
.map_err(|e| ErrorBuilder::new(ErrorCode::DocIdInvalid).msg(e).build())?
2021-07-22 21:43:01 +08:00
.0;
Ok(CreateDocParams { id, data: self.data })
2021-07-22 21:43:01 +08:00
}
}
2021-07-22 22:26:38 +08:00
#[derive(ProtoBuf, Default, Debug, Clone)]
pub struct Doc {
2021-07-22 22:26:38 +08:00
#[pb(index = 1)]
pub id: String,
#[pb(index = 2)]
pub data: String,
2021-07-22 22:26:38 +08:00
}