From 3e583315b31e2aa674548195ba786ca0014b9459 Mon Sep 17 00:00:00 2001 From: Richard Shiue <71320345+richardshiue@users.noreply.github.com> Date: Wed, 18 Dec 2024 22:28:00 +0800 Subject: [PATCH] chore: apply code suggestions to 2 files --- libs/client-api/src/http_chat.rs | 6 ++---- src/api/chat.rs | 15 ++++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/libs/client-api/src/http_chat.rs b/libs/client-api/src/http_chat.rs index 6546ba0fa..dc5401217 100644 --- a/libs/client-api/src/http_chat.rs +++ b/libs/client-api/src/http_chat.rs @@ -268,17 +268,15 @@ impl Client { chat_id: &str, answer_message_id: i64, ) -> Result, AppResponseError> { - let mut url = format!( + let url = format!( "{}/api/chat/{workspace_id}/{chat_id}/message/find_question", self.base_url ); - let query_params = vec![("answer_message_id", answer_message_id.to_string())]; - let query = serde_urlencoded::to_string(&query_params).unwrap(); - url = format!("{}?{}", url, query); let resp = self .http_client_with_auth(Method::GET, &url) .await? + .query(&[("answer_message_id", answer_message_id)]) .send() .await?; AppResponse::>::from_response(resp) diff --git a/src/api/chat.rs b/src/api/chat.rs index beb71e1fd..67dc1fabc 100644 --- a/src/api/chat.rs +++ b/src/api/chat.rs @@ -5,6 +5,7 @@ use crate::biz::chat::ops::{ use crate::state::AppState; use actix_web::web::{Data, Json}; use actix_web::{web, HttpRequest, HttpResponse, Scope}; +use serde::Deserialize; use crate::api::util::ai_model_from_header; use app_error::AppError; @@ -356,16 +357,11 @@ async fn get_chat_message_handler( #[instrument(level = "debug", skip_all, err)] async fn get_chat_question_message_handler( path: web::Path<(String, String)>, - query: web::Query>, + query: web::Query, state: Data, ) -> actix_web::Result>> { - let answer_message_id = query - .get("answer_message_id") - .and_then(|s| s.parse::().ok()) - .ok_or_else(|| AppError::InvalidRequest(serde_json::to_string(&query.0).unwrap()))?; - let (_workspace_id, chat_id) = path.into_inner(); - let message = get_question_message(&state.pg_pool, &chat_id, answer_message_id).await?; + let message = get_question_message(&state.pg_pool, &chat_id, query.0.answer_message_id).await?; Ok(AppResponse::Ok().with_data(message).into()) } @@ -521,3 +517,8 @@ where } } } + +#[derive(Debug, Deserialize)] +struct FindQuestionParams { + answer_message_id: i64, +}