2022-04-18 17:17:42 +08:00
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
use flowy_error::ErrorCode;
|
|
|
|
use flowy_grid_data_model::parser::NotEmptyStr;
|
|
|
|
|
2022-07-25 13:15:11 +08:00
|
|
|
#[derive(Debug, Default, Clone, ProtoBuf)]
|
2022-08-11 13:25:55 +08:00
|
|
|
pub struct RowIdPB {
|
2022-04-18 17:17:42 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub grid_id: String,
|
|
|
|
|
2022-07-02 00:10:13 +08:00
|
|
|
#[pb(index = 2)]
|
|
|
|
pub block_id: String,
|
|
|
|
|
2022-04-18 17:17:42 +08:00
|
|
|
#[pb(index = 3)]
|
|
|
|
pub row_id: String,
|
|
|
|
}
|
|
|
|
|
2022-08-11 13:25:55 +08:00
|
|
|
pub struct RowIdParams {
|
2022-04-18 17:17:42 +08:00
|
|
|
pub grid_id: String,
|
2022-07-02 00:10:13 +08:00
|
|
|
pub block_id: String,
|
2022-04-18 17:17:42 +08:00
|
|
|
pub row_id: String,
|
|
|
|
}
|
|
|
|
|
2022-08-11 13:25:55 +08:00
|
|
|
impl TryInto<RowIdParams> for RowIdPB {
|
2022-04-18 17:17:42 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
2022-08-11 13:25:55 +08:00
|
|
|
fn try_into(self) -> Result<RowIdParams, Self::Error> {
|
2022-04-18 17:17:42 +08:00
|
|
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
2022-07-03 15:53:28 +08:00
|
|
|
let block_id = NotEmptyStr::parse(self.block_id).map_err(|_| ErrorCode::BlockIdIsEmpty)?;
|
2022-04-18 17:17:42 +08:00
|
|
|
let row_id = NotEmptyStr::parse(self.row_id).map_err(|_| ErrorCode::RowIdIsEmpty)?;
|
|
|
|
|
2022-08-11 13:25:55 +08:00
|
|
|
Ok(RowIdParams {
|
2022-04-18 17:17:42 +08:00
|
|
|
grid_id: grid_id.0,
|
2022-07-03 15:53:28 +08:00
|
|
|
block_id: block_id.0,
|
2022-04-18 17:17:42 +08:00
|
|
|
row_id: row_id.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2022-07-01 20:32:11 +08:00
|
|
|
|
2022-07-02 00:10:13 +08:00
|
|
|
#[derive(Debug, Default, Clone, ProtoBuf)]
|
2022-07-17 13:38:53 +08:00
|
|
|
pub struct BlockRowIdPB {
|
2022-07-02 00:10:13 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub block_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub row_id: String,
|
|
|
|
}
|
|
|
|
|
2022-07-01 20:32:11 +08:00
|
|
|
#[derive(ProtoBuf, Default)]
|
2022-07-17 13:38:53 +08:00
|
|
|
pub struct CreateRowPayloadPB {
|
2022-07-01 20:32:11 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub grid_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2, one_of)]
|
|
|
|
pub start_row_id: Option<String>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct CreateRowParams {
|
|
|
|
pub grid_id: String,
|
|
|
|
pub start_row_id: Option<String>,
|
2022-08-15 20:07:01 +08:00
|
|
|
pub group_id: Option<String>,
|
2022-07-01 20:32:11 +08:00
|
|
|
}
|
|
|
|
|
2022-07-17 13:38:53 +08:00
|
|
|
impl TryInto<CreateRowParams> for CreateRowPayloadPB {
|
2022-07-01 20:32:11 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_into(self) -> Result<CreateRowParams, Self::Error> {
|
|
|
|
let grid_id = NotEmptyStr::parse(self.grid_id).map_err(|_| ErrorCode::GridIdIsEmpty)?;
|
|
|
|
Ok(CreateRowParams {
|
|
|
|
grid_id: grid_id.0,
|
|
|
|
start_row_id: self.start_row_id,
|
2022-08-15 20:07:01 +08:00
|
|
|
group_id: None,
|
2022-07-01 20:32:11 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|