Skip to content

Commit

Permalink
feat: api to add database view
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng committed Dec 5, 2024
1 parent e31928e commit 9738eab
Show file tree
Hide file tree
Showing 12 changed files with 818 additions and 209 deletions.
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 @@ -310,13 +310,13 @@ lto = false # Disable Link-Time Optimization
[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 = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "0efc824a6e1a56e4485646e6428c07fdccf6e918" }
collab = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "8bd376c0c71ce366d763a70385c7b445a98241ed" }
collab-entity = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "8bd376c0c71ce366d763a70385c7b445a98241ed" }
collab-folder = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "8bd376c0c71ce366d763a70385c7b445a98241ed" }
collab-document = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "8bd376c0c71ce366d763a70385c7b445a98241ed" }
collab-user = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "8bd376c0c71ce366d763a70385c7b445a98241ed" }
collab-database = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "8bd376c0c71ce366d763a70385c7b445a98241ed" }
collab-importer = { git = "https://github.com/AppFlowy-IO/AppFlowy-Collab", rev = "8bd376c0c71ce366d763a70385c7b445a98241ed" }

[features]
history = []
Expand Down
22 changes: 21 additions & 1 deletion libs/client-api/src/http_view.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use client_api_entity::workspace_dto::{
CreatePageParams, CreateSpaceParams, Page, PageCollab, Space, UpdatePageParams, UpdateSpaceParams,
CreatePageDatabaseViewParams, CreatePageParams, CreateSpaceParams, Page, PageCollab, Space,
UpdatePageParams, UpdateSpaceParams,
};
use reqwest::Method;
use serde_json::json;
Expand Down Expand Up @@ -148,4 +149,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 @@ -156,6 +156,12 @@ pub struct CreatePageParams {
pub name: Option<String>,
}

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

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct UpdatePageParams {
pub name: String,
Expand Down
27 changes: 26 additions & 1 deletion src/api/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ 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::{
create_page, create_space, get_page_view_collab, move_page_to_trash,
create_database_view, create_page, create_space, get_page_view_collab, move_page_to_trash,
restore_all_pages_from_trash, restore_page_from_trash, update_page, update_page_collab_data,
update_space,
};
Expand Down Expand Up @@ -149,6 +149,10 @@ pub fn workspace_scope() -> Scope {
web::resource("/{workspace_id}/page-view/{view_id}/restore-from-trash")
.route(web::post().to(restore_page_from_trash_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}/restore-all-pages-from-trash")
.route(web::post().to(restore_all_pages_from_trash_handler)),
Expand Down Expand Up @@ -1042,6 +1046,27 @@ async fn restore_all_pages_from_trash_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>,
) -> Result<Json<AppResponse<()>>> {
let uid = state.user_cache.get_user_uid(&user_uuid).await?;
let (workspace_uuid, view_id) = path.into_inner();
create_database_view(
&state.pg_pool,
&state.collab_access_control_storage,
uid,
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

0 comments on commit 9738eab

Please sign in to comment.