Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: api to create database view #1251

Merged
merged 1 commit into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -303,13 +303,13 @@ lto = false
[patch.crates-io]
# It's diffcult to resovle different version with the same crate used in AppFlowy Frontend and the Client-API crate.
# So using patch to workaround this issue.
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "7ea6f127429538e1c84a74c42ca087dc1a313bdd" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "7ea6f127429538e1c84a74c42ca087dc1a313bdd" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "7ea6f127429538e1c84a74c42ca087dc1a313bdd" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "7ea6f127429538e1c84a74c42ca087dc1a313bdd" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "7ea6f127429538e1c84a74c42ca087dc1a313bdd" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "7ea6f127429538e1c84a74c42ca087dc1a313bdd" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "7ea6f127429538e1c84a74c42ca087dc1a313bdd" }
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c2442a93704e14508ccee325da8d56ef0b34c7ce" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c2442a93704e14508ccee325da8d56ef0b34c7ce" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c2442a93704e14508ccee325da8d56ef0b34c7ce" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c2442a93704e14508ccee325da8d56ef0b34c7ce" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c2442a93704e14508ccee325da8d56ef0b34c7ce" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c2442a93704e14508ccee325da8d56ef0b34c7ce" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "c2442a93704e14508ccee325da8d56ef0b34c7ce" }

[features]
history = []
Expand Down
23 changes: 21 additions & 2 deletions libs/client-api/src/http_view.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use client_api_entity::workspace_dto::{
AppendBlockToPageParams, CreatePageParams, CreateSpaceParams, MovePageParams, Page, PageCollab,
PublishPageParams, Space, UpdatePageParams, UpdateSpaceParams,
AppendBlockToPageParams, CreatePageDatabaseViewParams, CreatePageParams, CreateSpaceParams,
MovePageParams, Page, PageCollab, PublishPageParams, Space, UpdatePageParams, UpdateSpaceParams,
};
use reqwest::Method;
use serde_json::json;
Expand Down Expand Up @@ -258,4 +258,23 @@ impl Client {
.await?;
AppResponse::<()>::from_response(resp).await?.into_error()
}

pub async fn create_database_view(
&self,
workspace_id: Uuid,
view_id: &str,
params: &CreatePageDatabaseViewParams,
) -> Result<(), AppResponseError> {
let url = format!(
"{}/api/workspace/{}/page-view/{}/database-view",
self.base_url, workspace_id, view_id
);
let resp = self
.http_client_with_auth(Method::POST, &url)
.await?
.json(params)
.send()
.await?;
AppResponse::<()>::from_response(resp).await?.into_error()
}
}
6 changes: 6 additions & 0 deletions libs/shared-entity/src/dto/workspace_dto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,12 @@ pub struct MovePageParams {
pub prev_view_id: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CreatePageDatabaseViewParams {
pub layout: ViewLayout,
pub name: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageCollabData {
pub encoded_collab: Vec<u8>,
Expand Down
36 changes: 33 additions & 3 deletions src/api/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ use crate::biz::workspace::ops::{
get_reactions_on_published_view, remove_comment_on_published_view, remove_reaction_on_comment,
};
use crate::biz::workspace::page_view::{
append_block_at_the_end_of_page, create_page, create_space, delete_all_pages_from_trash,
delete_trash, get_page_view_collab, move_page, move_page_to_trash, publish_page,
restore_all_pages_from_trash, restore_page_from_trash, unpublish_page, update_page,
append_block_at_the_end_of_page, create_database_view, create_page, create_space,
delete_all_pages_from_trash, delete_trash, get_page_view_collab, move_page, move_page_to_trash,
publish_page, restore_all_pages_from_trash, restore_page_from_trash, unpublish_page, update_page,
update_page_collab_data, update_space,
};
use crate::biz::workspace::publish::get_workspace_default_publish_view_info_meta;
Expand Down Expand Up @@ -184,6 +184,10 @@ pub fn workspace_scope() -> Scope {
web::resource("/{workspace_id}/page-view/{view_id}/move")
.route(web::post().to(move_page_handler)),
)
.service(
web::resource("/{workspace_id}/page-view/{view_id}/database-view")
.route(web::post().to(post_page_database_view_handler)),
)
.service(
web::resource("/{workspace_id}/page-view/{view_id}/move-to-trash")
.route(web::post().to(move_page_to_trash_handler)),
Expand Down Expand Up @@ -1468,6 +1472,32 @@ async fn unpublish_page_handler(
Ok(Json(AppResponse::Ok()))
}

async fn post_page_database_view_handler(
user_uuid: UserUuid,
path: web::Path<(Uuid, String)>,
payload: Json<CreatePageDatabaseViewParams>,
state: Data<AppState>,
server: Data<RealtimeServerAddr>,
req: HttpRequest,
) -> Result<Json<AppResponse<()>>> {
let uid = state.user_cache.get_user_uid(&user_uuid).await?;
let user = realtime_user_for_web_request(req.headers(), uid)?;
let (workspace_uuid, view_id) = path.into_inner();
create_database_view(
&state.metrics.appflowy_web_metrics,
server,
user,
&state.pg_pool,
&state.collab_access_control_storage,
workspace_uuid,
&view_id,
&payload.layout,
payload.name.as_deref(),
)
.await?;
Ok(Json(AppResponse::Ok()))
}

async fn update_page_view_handler(
user_uuid: UserUuid,
path: web::Path<(Uuid, String)>,
Expand Down
Loading
Loading