use axum::{extract::{Path, State}, http::StatusCode, Json}; use uuid::Uuid; use api_types::requests::SetTopFriendsRequest; use application::use_cases::social::*; use application::use_cases::profile::{get_top_friends, set_top_friends, get_user_by_username}; use domain::value_objects::{ThoughtId, UserId}; use crate::{errors::ApiError, extractors::AuthUser, state::AppState}; pub async fn post_like(State(s): State, AuthUser(uid): AuthUser, Path(id): Path) -> Result { like_thought(&*s.likes, &*s.events, &uid, &ThoughtId::from_uuid(id)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn delete_like(State(s): State, AuthUser(uid): AuthUser, Path(id): Path) -> Result { unlike_thought(&*s.likes, &*s.events, &uid, &ThoughtId::from_uuid(id)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn post_boost(State(s): State, AuthUser(uid): AuthUser, Path(id): Path) -> Result { boost_thought(&*s.boosts, &*s.events, &uid, &ThoughtId::from_uuid(id)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn delete_boost(State(s): State, AuthUser(uid): AuthUser, Path(id): Path) -> Result { unboost_thought(&*s.boosts, &*s.events, &uid, &ThoughtId::from_uuid(id)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn post_follow(State(s): State, AuthUser(uid): AuthUser, Path(target): Path) -> Result { follow_user(&*s.follows, &*s.events, &uid, &UserId::from_uuid(target)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn delete_follow(State(s): State, AuthUser(uid): AuthUser, Path(target): Path) -> Result { unfollow_user(&*s.follows, &*s.events, &uid, &UserId::from_uuid(target)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn post_block(State(s): State, AuthUser(uid): AuthUser, Path(target): Path) -> Result { block_user(&*s.blocks, &*s.events, &uid, &UserId::from_uuid(target)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn delete_block(State(s): State, AuthUser(uid): AuthUser, Path(target): Path) -> Result { unblock_user(&*s.blocks, &uid, &UserId::from_uuid(target)).await?; Ok(StatusCode::NO_CONTENT) } pub async fn put_top_friends(State(s): State, AuthUser(uid): AuthUser, Json(body): Json) -> Result { let ids: Vec = body.friend_ids.into_iter().map(UserId::from_uuid).collect(); set_top_friends(&*s.top_friends, &uid, ids).await?; Ok(StatusCode::NO_CONTENT) } pub async fn get_top_friends_handler(State(s): State, Path(username): Path) -> Result, ApiError> { let user = get_user_by_username(&*s.users, &username).await?; let friends = get_top_friends(&*s.top_friends, &user.id).await?; let ids: Vec = friends.iter().map(|(tf, _)| tf.friend_id.as_uuid()).collect(); Ok(Json(serde_json::json!({ "top_friends": ids }))) }