feat(presentation): add utoipa::path annotations to all handlers

This commit is contained in:
2026-05-14 11:34:02 +02:00
parent 4f990afe5e
commit 137d1a0c6a
8 changed files with 141 additions and 4 deletions

View File

@@ -1,19 +1,44 @@
use axum::{extract::{Path, State}, Json};
use api_types::{requests::UpdateProfileRequest, responses::UserResponse};
use api_types::{requests::UpdateProfileRequest, responses::{ErrorResponse, UserResponse}};
use application::use_cases::profile::{get_user_by_username, update_profile};
use crate::{errors::ApiError, extractors::AuthUser, handlers::auth::to_user_response, state::AppState};
#[utoipa::path(
get, path = "/users/{username}",
params(("username" = String, Path, description = "Username")),
responses(
(status = 200, body = UserResponse),
(status = 404, description = "User not found", body = ErrorResponse),
)
)]
pub async fn get_user(State(s): State<AppState>, Path(username): Path<String>) -> Result<Json<UserResponse>, ApiError> {
let user = get_user_by_username(&*s.users, &username).await?;
Ok(Json(to_user_response(&user)))
}
#[utoipa::path(
patch, path = "/users/me",
request_body = UpdateProfileRequest,
responses(
(status = 200, body = UserResponse),
(status = 401, description = "Unauthorized", body = ErrorResponse),
),
security(("bearer_auth" = []))
)]
pub async fn patch_profile(State(s): State<AppState>, AuthUser(uid): AuthUser, Json(body): Json<UpdateProfileRequest>) -> Result<Json<UserResponse>, ApiError> {
update_profile(&*s.users, &uid, body.display_name, body.bio, body.avatar_url, body.header_url, body.custom_css).await?;
let user = s.users.find_by_id(&uid).await?.ok_or(domain::errors::DomainError::NotFound)?;
Ok(Json(to_user_response(&user)))
}
#[utoipa::path(
get, path = "/users/me",
responses(
(status = 200, body = UserResponse),
(status = 401, description = "Unauthorized", body = ErrorResponse),
),
security(("bearer_auth" = []))
)]
pub async fn get_me(State(s): State<AppState>, AuthUser(uid): AuthUser) -> Result<Json<UserResponse>, ApiError> {
let user = s.users.find_by_id(&uid).await?.ok_or(domain::errors::DomainError::NotFound)?;
Ok(Json(to_user_response(&user)))