use actix_web::{HttpResponse, web}; use crate::api::response::{ApiErrorResponse, ApiResponse}; use crate::error::AppError; use crate::models::users::UserProfile; use crate::service::AppService; use crate::service::user::profile::UpdateUserProfileParams; use crate::session::Session; /// Update user profile /// /// Updates the authenticated user's public profile information. /// Requires authentication. /// /// Updatable fields: /// - full_name: Full legal name or display name /// - company: Organization or company name /// - location: Geographic location (e.g., "San Francisco, CA") /// - website_url: Personal or company website URL /// - twitter_username: Twitter/X handle /// - timezone: IANA timezone identifier (e.g., "America/New_York") /// - language: Preferred language code (e.g., "en", "zh-CN") /// - profile_readme: Markdown content for profile README /// /// All fields are optional; only provided fields are updated. /// Returns the updated profile with all fields. #[utoipa::path( put, path = "/api/v1/user/profile", tag = "User", operation_id = "userUpdateProfile", request_body( content = UpdateUserProfileParams, description = "Profile update parameters (all fields optional)", content_type = "application/json" ), responses( (status = 200, description = "Profile updated successfully. Returns all updated profile fields.", body = ApiResponse), (status = 400, description = "Invalid parameters", body = ApiErrorResponse), (status = 401, description = "Authentication required or session expired", body = ApiErrorResponse), (status = 500, description = "Internal server error", body = ApiErrorResponse), ), security( ("session_cookie" = []) ) )] pub async fn update_profile( service: web::Data, session: Session, params: web::Json, ) -> Result { let profile = service .user .user_update_profile(&session, params.into_inner()) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(profile))) }