fix: share query param struct for api client and server

This commit is contained in:
khorshuheng 2024-07-29 10:51:16 +08:00
parent 62f32e8757
commit ea8ca36b5b
4 changed files with 16 additions and 15 deletions

View File

@ -1,7 +1,7 @@
use bytes::Bytes;
use client_api_entity::{
CreateGlobalCommentParams, CreateReactionParams, DeleteGlobalCommentParams, DeleteReactionParams,
GlobalComments, PublishInfo, Reactions, UpdatePublishNamespace,
GetReactionQueryParams, GlobalComments, PublishInfo, Reactions, UpdatePublishNamespace,
};
use reqwest::Method;
use shared_entity::response::{AppResponse, AppResponseError};
@ -259,12 +259,14 @@ impl Client {
"{}/api/workspace/published-info/{}/reaction",
self.base_url, view_id
);
let url = if let Some(comment_id) = comment_id {
format!("{}?comment_id={}", url, comment_id)
} else {
url
};
let resp = self.cloud_client.get(&url).send().await?;
let resp = self
.cloud_client
.get(url)
.query(&GetReactionQueryParams {
comment_id: *comment_id,
})
.send()
.await?;
AppResponse::<Reactions>::from_response(resp)
.await?
.into_data()

View File

@ -890,6 +890,11 @@ pub struct Reaction {
pub comment_id: Uuid,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct GetReactionQueryParams {
pub comment_id: Option<Uuid>,
}
#[derive(Serialize, Deserialize, Debug)]
pub struct CreateReactionParams {
pub reaction_type: String,

View File

@ -1263,7 +1263,7 @@ pub async fn select_reactions_for_published_view<'a, E: Executor<'a, Database =
})
.or_default();
users.push(AFWebUser {
uid: row.user_uuid.clone(),
uid: row.user_uuid,
name: row.user_name.clone(),
avatar_url: None,
});

View File

@ -13,7 +13,6 @@ use collab::entity::EncodedCollab;
use collab_entity::CollabType;
use futures_util::future::try_join_all;
use prost::Message as ProstMessage;
use serde::Deserialize;
use sqlx::types::uuid;
use tokio::time::Instant;
use tokio_stream::StreamExt;
@ -1135,14 +1134,9 @@ async fn delete_published_collab_comment_handler(
Ok(Json(AppResponse::Ok()))
}
#[derive(Deserialize)]
struct GetReactionQuery {
comment_id: Option<Uuid>,
}
async fn get_published_collab_reaction_handler(
view_id: web::Path<Uuid>,
query: web::Query<GetReactionQuery>,
query: web::Query<GetReactionQueryParams>,
state: Data<AppState>,
) -> Result<JsonAppResponse<Reactions>> {
let view_id = view_id.into_inner();