From 6082766935562ee7d9653dfd5e6f7d3647297224 Mon Sep 17 00:00:00 2001 From: Gabriel Kaszewski Date: Thu, 14 May 2026 11:20:48 +0200 Subject: [PATCH] feat(presentation): GET /users/me, GET /users/{username}/thoughts, GET /tags/{name} --- crates/presentation/src/handlers/feed.rs | 48 ++++++++++++++++++++++- crates/presentation/src/handlers/users.rs | 5 +++ crates/presentation/src/routes.rs | 4 +- 3 files changed, 55 insertions(+), 2 deletions(-) diff --git a/crates/presentation/src/handlers/feed.rs b/crates/presentation/src/handlers/feed.rs index 1e4bae9..ea5b351 100644 --- a/crates/presentation/src/handlers/feed.rs +++ b/crates/presentation/src/handlers/feed.rs @@ -1,6 +1,6 @@ use axum::{extract::{Path, Query, State}, Json}; use api_types::requests::{PaginationQuery, SearchQuery}; -use application::use_cases::feed::{get_home_feed, get_public_feed, get_followers, get_following}; +use application::use_cases::feed::{get_home_feed, get_public_feed, get_followers, get_following, get_user_feed, get_by_tag}; use domain::models::feed::PageParams; use crate::{errors::ApiError, extractors::{AuthUser, OptionalAuthUser}, handlers::auth::to_user_response, state::AppState}; use application::use_cases::profile::get_user_by_username; @@ -62,3 +62,49 @@ pub async fn get_followers_handler(State(s): State, Path(username): Pa let result = get_followers(&*s.follows, &user.id, page).await?; Ok(Json(serde_json::json!({ "total": result.total, "items": result.items.iter().map(to_user_response).collect::>() }))) } + +pub async fn user_thoughts_handler( + State(s): State, + Path(username): Path, + Query(q): Query, +) -> Result, ApiError> { + let user = get_user_by_username(&*s.users, &username).await?; + let page = PageParams { page: q.page(), per_page: q.per_page() }; + let result = get_user_feed(&*s.thoughts, &user.id, page).await?; + Ok(Json(serde_json::json!({ + "total": result.total, + "page": result.page, + "per_page": result.per_page, + "items": result.items.iter().map(|e| serde_json::json!({ + "id": e.thought.id.as_uuid(), + "content": e.thought.content.as_str(), + "visibility": e.thought.visibility.as_str(), + "like_count": e.like_count, + "boost_count": e.boost_count, + "reply_count": e.reply_count, + "created_at": e.thought.created_at, + "updated_at": e.thought.updated_at, + })).collect::>() + }))) +} + +pub async fn tag_thoughts_handler( + State(s): State, + Path(tag_name): Path, + Query(q): Query, +) -> Result, ApiError> { + let page = PageParams { page: q.page(), per_page: q.per_page() }; + let result = get_by_tag(&*s.tags, &tag_name, page).await?; + Ok(Json(serde_json::json!({ + "tag": tag_name, + "total": result.total, + "page": result.page, + "per_page": result.per_page, + "items": result.items.iter().map(|t| serde_json::json!({ + "id": t.id.as_uuid(), + "content": t.content.as_str(), + "visibility": t.visibility.as_str(), + "created_at": t.created_at, + })).collect::>() + }))) +} diff --git a/crates/presentation/src/handlers/users.rs b/crates/presentation/src/handlers/users.rs index 43532ba..c0dce3f 100644 --- a/crates/presentation/src/handlers/users.rs +++ b/crates/presentation/src/handlers/users.rs @@ -13,3 +13,8 @@ pub async fn patch_profile(State(s): State, AuthUser(uid): AuthUser, J let user = s.users.find_by_id(&uid).await?.ok_or(domain::errors::DomainError::NotFound)?; Ok(Json(to_user_response(&user))) } + +pub async fn get_me(State(s): State, AuthUser(uid): AuthUser) -> Result, ApiError> { + let user = s.users.find_by_id(&uid).await?.ok_or(domain::errors::DomainError::NotFound)?; + Ok(Json(to_user_response(&user))) +} diff --git a/crates/presentation/src/routes.rs b/crates/presentation/src/routes.rs index 4302dc1..f8072cb 100644 --- a/crates/presentation/src/routes.rs +++ b/crates/presentation/src/routes.rs @@ -20,7 +20,7 @@ pub fn router(fed_config: &ApFederationConfig) -> Router { .route("/auth/register", post(auth::post_register)) .route("/auth/login", post(auth::post_login)) // users — static paths before parameterised - .route("/users/me", patch(users::patch_profile)) + .route("/users/me", get(users::get_me).patch(users::patch_profile)) .route("/users/me/top-friends", put(social::put_top_friends)) .route("/users/{username}/top-friends", get(social::get_top_friends_handler)) // follows & blocks (use {id} param) @@ -54,6 +54,8 @@ pub fn router(fed_config: &ApFederationConfig) -> Router { .route("/feed", get(feed::home_feed)) .route("/feed/public", get(feed::public_feed)) .route("/search", get(feed::search_handler)) + .route("/users/{username}/thoughts", get(feed::user_thoughts_handler)) + .route("/tags/{name}", get(feed::tag_thoughts_handler)) // notifications .route("/notifications", get(notifications::list_notifications)) .route("/notifications/read-all", post(notifications::mark_all_read))