use actix_web::{HttpResponse, web}; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::users::User; use crate::service::AppService; use crate::service::user::account::UpdateUserAccountParams; use crate::session::Session; /// Update user account /// /// Updates the authenticated user's account settings. /// Requires authentication. /// /// Updatable fields: /// - username: New username (must be unique across the platform) /// - display_name: Human-readable display name /// - bio: Short biography text /// - visibility: Profile visibility ("public", "private", or "internal") /// /// All fields are optional; only provided fields are updated. /// Returns the updated user account with all metadata. #[utoipa::path( put, path = "/api/v1/user/account", tag = "User", operation_id = "userUpdateAccount", request_body( content = UpdateUserAccountParams, description = "Account update parameters (all fields optional)", content_type = "application/json" ), responses( (status = 200, description = "Account updated successfully. Returns updated user account with all metadata.", body = ApiResponse), (status = 400, description = "Invalid parameters: empty username or unsupported visibility value", body = ApiErrorResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 404, description = "User not found", body = ApiErrorResponse), (status = 409, description = "Username already taken", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn update_account( service: web::Data, session: Session, params: web::Json, ) -> Result { let user = service .user .user_update_account(&session, params.into_inner()) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(user))) }