Skip to content

Commit

Permalink
chore: apply code suggestions to 2 files
Browse files Browse the repository at this point in the history
  • Loading branch information
richardshiue committed Dec 18, 2024
1 parent cfab4a8 commit 3e58331
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
6 changes: 2 additions & 4 deletions libs/client-api/src/http_chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,15 @@ impl Client {
chat_id: &str,
answer_message_id: i64,
) -> Result<Option<ChatMessage>, 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::<Option<ChatMessage>>::from_response(resp)
Expand Down
15 changes: 8 additions & 7 deletions src/api/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<HashMap<String, String>>,
query: web::Query<FindQuestionParams>,
state: Data<AppState>,
) -> actix_web::Result<JsonAppResponse<Option<ChatMessage>>> {
let answer_message_id = query
.get("answer_message_id")
.and_then(|s| s.parse::<i64>().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())
}

Expand Down Expand Up @@ -521,3 +517,8 @@ where
}
}
}

#[derive(Debug, Deserialize)]
struct FindQuestionParams {
answer_message_id: i64,
}

0 comments on commit 3e58331

Please sign in to comment.