From 29e4af26d8dff12daafbf335db714a222f9f2757 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Sat, 16 May 2026 02:08:22 +0200 Subject: [PATCH] =?UTF-8?q?fix(api):=20top-friends=20endpoint=20returns=20?= =?UTF-8?q?full=20UserResponse=20=E2=80=94=20eliminates=20frontend=20N+1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/presentation/src/handlers/social.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/presentation/src/handlers/social.rs b/crates/presentation/src/handlers/social.rs index b3bc334..7fbb1bd 100644 --- a/crates/presentation/src/handlers/social.rs +++ b/crates/presentation/src/handlers/social.rs @@ -4,6 +4,8 @@ use crate::{ state::AppState, }; use api_types::requests::SetTopFriendsRequest; +use api_types::responses::TopFriendsResponse; +use crate::handlers::auth::to_user_response; use application::use_cases::profile::{get_top_friends, get_user_by_username, set_top_friends}; use application::use_cases::social::*; use axum::{ @@ -155,15 +157,17 @@ pub async fn put_top_friends( set_top_friends(&*d.top_friends, &uid, ids).await?; Ok(StatusCode::NO_CONTENT) } -#[utoipa::path(get, path = "/users/{username}/top-friends", params(("username" = String, Path, description = "Username")), responses((status = 200, description = "Top friends list")))] +#[utoipa::path(get, path = "/users/{username}/top-friends", + params(("username" = String, Path, description = "Username")), + responses((status = 200, description = "Top friends list", body = TopFriendsResponse)))] pub async fn get_top_friends_handler( Deps(d): Deps, Path(username): Path, -) -> Result, ApiError> { +) -> Result, ApiError> { let user = get_user_by_username(&*d.users, &username).await?; let friends = get_top_friends(&*d.top_friends, &user.id).await?; - let usernames: Vec<&str> = friends.iter().map(|(_, u)| u.username.as_str()).collect(); - Ok(Json(serde_json::json!({ "topFriends": usernames }))) + let top_friends = friends.iter().map(|(_, u)| to_user_response(u)).collect(); + Ok(Json(TopFriendsResponse { top_friends })) } #[cfg(test)]