Skip to content

Commit

Permalink
feat: add endpoint for getting page view collab (#831)
Browse files Browse the repository at this point in the history
  • Loading branch information
khorshuheng authored Sep 18, 2024
1 parent 44d76bb commit 0b193e1
Show file tree
Hide file tree
Showing 10 changed files with 410 additions and 2 deletions.

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

27 changes: 27 additions & 0 deletions libs/client-api/src/http_view.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
use client_api_entity::workspace_dto::PageCollab;
use reqwest::Method;
use shared_entity::response::{AppResponse, AppResponseError};
use uuid::Uuid;

use crate::Client;

impl Client {
pub async fn get_workspace_page_view(
&self,
workspace_id: Uuid,
view_id: Uuid,
) -> Result<PageCollab, AppResponseError> {
let url = format!(
"{}/api/workspace/{}/page_view/{}",
self.base_url, workspace_id, view_id
);
let resp = self
.http_client_with_auth(Method::GET, &url)
.await?
.send()
.await?;
AppResponse::<PageCollab>::from_response(resp)
.await?
.into_data()
}
}
1 change: 1 addition & 0 deletions libs/client-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod http_history;
mod http_member;
mod http_publish;
mod http_template;
mod http_view;
pub use http::*;

#[cfg(feature = "collab-sync")]
Expand Down
20 changes: 20 additions & 0 deletions libs/database/src/user.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use database_entity::dto::AFWebUser;
use futures_util::stream::BoxStream;
use sqlx::postgres::PgArguments;
use sqlx::types::JsonValue;
Expand Down Expand Up @@ -240,3 +241,22 @@ pub async fn select_name_from_uuid(pool: &PgPool, user_uuid: &Uuid) -> Result<St
.await?;
Ok(email)
}

pub async fn select_web_user_from_uid(pool: &PgPool, uid: i64) -> Result<AFWebUser, AppError> {
let row = sqlx::query_as!(
AFWebUser,
r#"
SELECT
uuid,
name,
metadata ->> 'icon_url' AS avatar_url
FROM af_user
WHERE uid = $1
"#,
uid
)
.fetch_one(pool)
.await?;

Ok(row)
}
18 changes: 16 additions & 2 deletions libs/shared-entity/src/dto/workspace_dto.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use chrono::{DateTime, Utc};
use collab_entity::{CollabType, EncodedCollab};
use database_entity::dto::{AFRole, AFWorkspaceInvitationStatus};
use database_entity::dto::{AFRole, AFWebUser, AFWorkspaceInvitationStatus};
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
use std::ops::Deref;
use std::{collections::HashMap, ops::Deref};
use uuid::Uuid;

#[derive(Deserialize, Serialize)]
Expand Down Expand Up @@ -122,6 +122,20 @@ pub struct CollabResponse {
pub object_id: String,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageCollabData {
pub encoded_collab: Vec<u8>,
pub row_data: HashMap<String, Vec<u8>>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PageCollab {
pub view: FolderView,
pub data: PageCollabData,
pub owner: Option<AFWebUser>,
pub last_editor: Option<AFWebUser>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PublishedDuplicate {
pub published_view_id: String,
Expand Down
27 changes: 27 additions & 0 deletions src/api/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use crate::biz::workspace::ops::{
create_comment_on_published_view, create_reaction_on_comment, get_comments_on_published_view,
get_reactions_on_published_view, remove_comment_on_published_view, remove_reaction_on_comment,
};
use crate::biz::workspace::page_view::get_page_view_collab;
use crate::domain::compression::{
blocking_decompress, decompress, CompressionType, X_COMPRESSION_TYPE,
};
Expand Down Expand Up @@ -117,6 +118,10 @@ pub fn workspace_scope() -> Scope {
web::resource("/v1/{workspace_id}/collab/{object_id}")
.route(web::get().to(v1_get_collab_handler)),
)
.service(
web::resource("/{workspace_id}/page_view/{view_id}")
.route(web::get().to(get_page_view_handler)),
)
.service(
web::resource("/{workspace_id}/batch/collab")
.route(web::post().to(batch_create_collab_handler)),
Expand Down Expand Up @@ -776,6 +781,28 @@ async fn v1_get_collab_handler(
Ok(Json(AppResponse::Ok().with_data(resp)))
}

async fn get_page_view_handler(
user_uuid: UserUuid,
path: web::Path<(Uuid, String)>,
state: Data<AppState>,
) -> Result<Json<AppResponse<PageCollab>>> {
let (workspace_uuid, view_id) = path.into_inner();
let uid = state
.user_cache
.get_user_uid(&user_uuid)
.await
.map_err(AppResponseError::from)?;
let page_collab = get_page_view_collab(
&state.pg_pool,
state.collab_access_control_storage.clone(),
uid,
workspace_uuid,
&view_id,
)
.await?;
Ok(Json(AppResponse::Ok().with_data(page_collab)))
}

#[instrument(level = "trace", skip_all, err)]
async fn get_collab_snapshot_handler(
payload: Json<QuerySnapshotParams>,
Expand Down
1 change: 1 addition & 0 deletions src/biz/workspace/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod access_control;
pub mod ops;
pub mod page_view;
pub mod publish;
pub mod publish_dup;
Loading

0 comments on commit 0b193e1

Please sign in to comment.