feat: add 'move page', 'duplicate page', 'update space' and 'create space' api in client-api

This commit is contained in:
Lucas.Xu 2025-03-17 21:35:18 +08:00
parent e9ac91c4ed
commit bdbbb7c821
2 changed files with 153 additions and 0 deletions

View file

@ -2,8 +2,11 @@ use crate::notify::{ClientToken, TokenStateReceiver};
use app_error::AppError;
use app_error::ErrorCode;
use client_api_entity::auth_dto::CreateNewPageParams;
use client_api_entity::auth_dto::CreateNewSpaceParams;
use client_api_entity::auth_dto::DeleteUserQuery;
use client_api_entity::auth_dto::MovePageParams;
use client_api_entity::auth_dto::UpdatePageParams;
use client_api_entity::auth_dto::UpdateSpaceParams;
use client_api_entity::server_info_dto::ServerInfoResponseItem;
use client_api_entity::workspace_dto::FavoriteSectionItems;
use client_api_entity::workspace_dto::RecentSectionItems;
@ -1183,6 +1186,108 @@ impl Client {
log_request_id(&resp);
AppResponse::<()>::from_response(resp).await?.into_error()
}
/// Move the existing page to trash.
#[instrument(level = "info", skip_all, err)]
pub async fn move_page_to_trash(
&self,
workspace_id: &str,
page_id: &str,
) -> Result<(), AppResponseError> {
let url = format!(
"{}/api/workspace/{}/page-view/{}/move-to-trash",
self.base_url, workspace_id, page_id
);
let resp = self
.http_client_with_auth(Method::POST, &url)
.await?
.send()
.await?;
log_request_id(&resp);
AppResponse::<()>::from_response(resp).await?.into_error()
}
/// Move the existing page to another folder view.
#[instrument(level = "info", skip_all, err)]
pub async fn move_page(
&self,
workspace_id: &str,
page_id: &str,
params: MovePageParams,
) -> Result<(), AppResponseError> {
let url = format!(
"{}/api/workspace/{}/page-view/{}/move",
self.base_url, workspace_id, page_id
);
let resp = self
.http_client_with_auth(Method::POST, &url)
.await?
.json(&params)
.send()
.await?;
log_request_id(&resp);
AppResponse::<()>::from_response(resp).await?.into_error()
}
/// Duplicate the existing page.
#[instrument(level = "info", skip_all, err)]
pub async fn duplicate_page(
&self,
workspace_id: &str,
page_id: &str,
) -> Result<(), AppResponseError> {
let url = format!(
"{}/api/workspace/{}/page-view/{}/duplicate",
self.base_url, workspace_id, page_id
);
let resp = self
.http_client_with_auth(Method::POST, &url)
.await?
.send()
.await?;
log_request_id(&resp);
AppResponse::<()>::from_response(resp).await?.into_error()
}
/// Create a new space.
#[instrument(level = "info", skip_all, err)]
pub async fn create_new_space(
&self,
workspace_id: &str,
params: CreateNewSpaceParams,
) -> Result<(), AppResponseError> {
let url = format!("{}/api/workspace/{}/space", self.base_url, workspace_id);
let resp = self
.http_client_with_auth(Method::POST, &url)
.await?
.json(&params)
.send()
.await?;
log_request_id(&resp);
AppResponse::<()>::from_response(resp).await?.into_error()
}
/// Update the existing space.
#[instrument(level = "info", skip_all, err)]
pub async fn update_space(
&self,
workspace_id: &str,
space_id: &str,
params: UpdateSpaceParams,
) -> Result<(), AppResponseError> {
let url = format!(
"{}/api/workspace/{}/space/{}",
self.base_url, workspace_id, space_id
);
let resp = self
.http_client_with_auth(Method::PATCH, &url)
.await?
.json(&params)
.send()
.await?;
log_request_id(&resp);
AppResponse::<()>::from_response(resp).await?.into_error()
}
}
impl Display for Client {

View file

@ -82,6 +82,14 @@ pub struct CreateNewPageParams {
pub page_data: Option<serde_json::Value>,
}
#[derive(serde::Deserialize, serde::Serialize, Default)]
pub struct CreateNewSpaceParams {
pub name: String,
pub space_icon: String,
pub space_icon_color: String,
pub space_permission: u32, // 0: PublicToAll, 1: Private
}
#[derive(serde::Deserialize, serde::Serialize, Default)]
pub struct UpdatePageParams {
pub name: Option<String>,
@ -112,3 +120,43 @@ impl UpdatePageParams {
self
}
}
#[derive(serde::Deserialize, serde::Serialize, Default)]
pub struct UpdateSpaceParams {
pub space_permission: Option<u32>, // 0: PublicToAll, 1: Private
pub name: Option<String>,
pub space_icon: Option<ViewIcon>,
pub space_icon_color: Option<String>,
}
impl UpdateSpaceParams {
pub fn new() -> Self {
Self::default()
}
pub fn with_space_permission<T: Into<u32>>(mut self, space_permission: T) -> Self {
self.space_permission = Some(space_permission.into());
self
}
pub fn with_name<T: ToString>(mut self, name: T) -> Self {
self.name = Some(name.to_string());
self
}
pub fn with_space_icon<T: Into<ViewIcon>>(mut self, space_icon: T) -> Self {
self.space_icon = Some(space_icon.into());
self
}
pub fn with_space_icon_color<T: ToString>(mut self, space_icon_color: T) -> Self {
self.space_icon_color = Some(space_icon_color.to_string());
self
}
}
#[derive(serde::Deserialize, serde::Serialize, Default)]
pub struct MovePageParams {
pub new_parent_view_id: String,
pub prev_view_id: Option<String>,
}