2023-04-28 14:08:53 +08:00
|
|
|
use std::convert::TryInto;
|
|
|
|
|
|
|
|
use flowy_derive::ProtoBuf;
|
|
|
|
use flowy_error::ErrorCode;
|
|
|
|
|
|
|
|
use crate::entities::parser::NotEmptyStr;
|
2023-06-14 22:16:33 +08:00
|
|
|
use crate::entities::{FieldType, RowMetaPB};
|
2023-10-29 11:26:49 +08:00
|
|
|
use crate::services::group::{GroupChangeset, GroupData, GroupSetting};
|
2023-04-28 14:08:53 +08:00
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct GroupSettingPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub field_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<&GroupSetting> for GroupSettingPB {
|
|
|
|
fn from(rev: &GroupSetting) -> Self {
|
|
|
|
GroupSettingPB {
|
|
|
|
id: rev.id.clone(),
|
|
|
|
field_id: rev.field_id.clone(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct RepeatedGroupSettingPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<GroupSettingPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<Vec<GroupSettingPB>> for RepeatedGroupSettingPB {
|
|
|
|
fn from(items: Vec<GroupSettingPB>) -> Self {
|
|
|
|
Self { items }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<Vec<GroupSetting>> for RepeatedGroupSettingPB {
|
|
|
|
fn from(group_settings: Vec<GroupSetting>) -> Self {
|
|
|
|
RepeatedGroupSettingPB {
|
|
|
|
items: group_settings
|
|
|
|
.iter()
|
|
|
|
.map(|setting| setting.into())
|
|
|
|
.collect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-28 14:08:53 +08:00
|
|
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct RepeatedGroupPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub items: Vec<GroupPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::Deref for RepeatedGroupPB {
|
|
|
|
type Target = Vec<GroupPB>;
|
|
|
|
fn deref(&self) -> &Self::Target {
|
|
|
|
&self.items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::ops::DerefMut for RepeatedGroupPB {
|
|
|
|
fn deref_mut(&mut self) -> &mut Self::Target {
|
|
|
|
&mut self.items
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct GroupPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub group_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
2023-06-09 18:57:29 +08:00
|
|
|
pub group_name: String,
|
2023-04-28 14:08:53 +08:00
|
|
|
|
|
|
|
#[pb(index = 4)]
|
2023-06-14 22:16:33 +08:00
|
|
|
pub rows: Vec<RowMetaPB>,
|
2023-04-28 14:08:53 +08:00
|
|
|
|
|
|
|
#[pb(index = 5)]
|
|
|
|
pub is_default: bool,
|
|
|
|
|
|
|
|
#[pb(index = 6)]
|
|
|
|
pub is_visible: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl std::convert::From<GroupData> for GroupPB {
|
|
|
|
fn from(group_data: GroupData) -> Self {
|
|
|
|
Self {
|
|
|
|
field_id: group_data.field_id,
|
|
|
|
group_id: group_data.id,
|
2023-06-09 18:57:29 +08:00
|
|
|
group_name: group_data.name,
|
2023-08-28 13:28:24 +08:00
|
|
|
rows: group_data.rows.into_iter().map(RowMetaPB::from).collect(),
|
2023-04-28 14:08:53 +08:00
|
|
|
is_default: group_data.is_default,
|
|
|
|
is_visible: group_data.is_visible,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
2023-05-28 22:54:03 +08:00
|
|
|
pub struct GroupByFieldPayloadPB {
|
2023-04-28 14:08:53 +08:00
|
|
|
#[pb(index = 1)]
|
|
|
|
pub field_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
2023-05-28 22:54:03 +08:00
|
|
|
pub view_id: String,
|
2023-04-28 14:08:53 +08:00
|
|
|
}
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
impl TryInto<GroupByFieldParams> for GroupByFieldPayloadPB {
|
2023-04-28 14:08:53 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
fn try_into(self) -> Result<GroupByFieldParams, Self::Error> {
|
2023-04-28 14:08:53 +08:00
|
|
|
let field_id = NotEmptyStr::parse(self.field_id)
|
|
|
|
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
|
|
|
.0;
|
|
|
|
let view_id = NotEmptyStr::parse(self.view_id)
|
|
|
|
.map_err(|_| ErrorCode::ViewIdIsInvalid)?
|
|
|
|
.0;
|
|
|
|
|
2023-06-09 18:57:29 +08:00
|
|
|
Ok(GroupByFieldParams { field_id, view_id })
|
2023-04-28 14:08:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
pub struct GroupByFieldParams {
|
|
|
|
pub field_id: String,
|
|
|
|
pub view_id: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DeleteGroupParams {
|
2023-04-28 14:08:53 +08:00
|
|
|
pub view_id: String,
|
|
|
|
pub field_id: String,
|
2023-05-28 22:54:03 +08:00
|
|
|
pub group_id: String,
|
2023-04-28 14:08:53 +08:00
|
|
|
pub field_type: FieldType,
|
|
|
|
}
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
#[derive(Eq, PartialEq, ProtoBuf, Debug, Default, Clone)]
|
|
|
|
pub struct UpdateGroupPB {
|
2023-04-28 14:08:53 +08:00
|
|
|
#[pb(index = 1)]
|
2023-05-28 22:54:03 +08:00
|
|
|
pub view_id: String,
|
2023-04-28 14:08:53 +08:00
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub group_id: String,
|
|
|
|
|
2023-10-26 03:38:37 +02:00
|
|
|
#[pb(index = 3)]
|
|
|
|
pub field_id: String,
|
2023-04-28 14:08:53 +08:00
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
#[pb(index = 4, one_of)]
|
2023-10-26 03:38:37 +02:00
|
|
|
pub name: Option<String>,
|
|
|
|
|
|
|
|
#[pb(index = 5, one_of)]
|
2023-05-28 22:54:03 +08:00
|
|
|
pub visible: Option<bool>,
|
2023-04-28 14:08:53 +08:00
|
|
|
}
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
impl TryInto<UpdateGroupParams> for UpdateGroupPB {
|
2023-04-28 14:08:53 +08:00
|
|
|
type Error = ErrorCode;
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
fn try_into(self) -> Result<UpdateGroupParams, Self::Error> {
|
2023-04-28 14:08:53 +08:00
|
|
|
let view_id = NotEmptyStr::parse(self.view_id)
|
|
|
|
.map_err(|_| ErrorCode::ViewIdIsInvalid)?
|
|
|
|
.0;
|
2023-05-28 22:54:03 +08:00
|
|
|
let group_id = NotEmptyStr::parse(self.group_id)
|
|
|
|
.map_err(|_| ErrorCode::GroupIdIsEmpty)?
|
|
|
|
.0;
|
2023-10-26 03:38:37 +02:00
|
|
|
let field_id = NotEmptyStr::parse(self.field_id)
|
|
|
|
.map_err(|_| ErrorCode::FieldIdIsEmpty)?
|
|
|
|
.0;
|
2023-04-28 14:08:53 +08:00
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
Ok(UpdateGroupParams {
|
2023-04-28 14:08:53 +08:00
|
|
|
view_id,
|
2023-05-28 22:54:03 +08:00
|
|
|
group_id,
|
2023-10-26 03:38:37 +02:00
|
|
|
field_id,
|
2023-05-28 22:54:03 +08:00
|
|
|
name: self.name,
|
|
|
|
visible: self.visible,
|
2023-04-28 14:08:53 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-28 22:54:03 +08:00
|
|
|
pub struct UpdateGroupParams {
|
2023-04-28 14:08:53 +08:00
|
|
|
pub view_id: String,
|
|
|
|
pub group_id: String,
|
2023-10-26 03:38:37 +02:00
|
|
|
pub field_id: String,
|
2023-05-28 22:54:03 +08:00
|
|
|
pub name: Option<String>,
|
|
|
|
pub visible: Option<bool>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<UpdateGroupParams> for GroupChangeset {
|
|
|
|
fn from(params: UpdateGroupParams) -> Self {
|
|
|
|
Self {
|
|
|
|
group_id: params.group_id,
|
2023-10-26 03:38:37 +02:00
|
|
|
field_id: params.field_id,
|
2023-05-28 22:54:03 +08:00
|
|
|
name: params.name,
|
|
|
|
visible: params.visible,
|
|
|
|
}
|
|
|
|
}
|
2023-04-28 14:08:53 +08:00
|
|
|
}
|
2023-11-06 16:17:05 +08:00
|
|
|
|
|
|
|
#[derive(Debug, Default, ProtoBuf)]
|
|
|
|
pub struct CreateGroupPayloadPB {
|
|
|
|
#[pb(index = 1)]
|
|
|
|
pub view_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 2)]
|
|
|
|
pub group_config_id: String,
|
|
|
|
|
|
|
|
#[pb(index = 3)]
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug, Clone)]
|
|
|
|
pub struct CreateGroupParams {
|
|
|
|
pub view_id: String,
|
|
|
|
pub group_config_id: String,
|
|
|
|
pub name: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TryFrom<CreateGroupPayloadPB> for CreateGroupParams {
|
|
|
|
type Error = ErrorCode;
|
|
|
|
|
|
|
|
fn try_from(value: CreateGroupPayloadPB) -> Result<Self, Self::Error> {
|
|
|
|
let view_id = NotEmptyStr::parse(value.view_id).map_err(|_| ErrorCode::ViewIdIsInvalid)?;
|
|
|
|
let name = NotEmptyStr::parse(value.name).map_err(|_| ErrorCode::ViewIdIsInvalid)?;
|
|
|
|
Ok(CreateGroupParams {
|
|
|
|
view_id: view_id.0,
|
|
|
|
group_config_id: value.group_config_id,
|
|
|
|
name: name.0,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|