use crate::{ApiResponse, error::ApiError}; use actix_web::{HttpResponse, Result, web}; use service::AppService; use session::Session; #[utoipa::path( get, path = "/api/users/me/profile", responses( (status = 200, description = "Get current user profile", body = ApiResponse), (status = 401, description = "Unauthorized"), ), tag = "User" )] pub async fn get_my_profile( service: web::Data, session: Session, ) -> Result { let resp = service.user_get_current_profile(&session).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( get, path = "/api/users/{username}", params(("username" = String, Path)), responses( (status = 200, description = "Get user profile", body = ApiResponse), (status = 401, description = "Unauthorized"), (status = 404, description = "Not found"), ), tag = "User" )] pub async fn get_profile_by_username( service: web::Data, path: web::Path, ) -> Result { let username = path.into_inner(); let resp = service.user_get_profile_by_username(username).await?; Ok(ApiResponse::ok(resp).to_response()) } #[utoipa::path( patch, path = "/api/users/me/profile", request_body = service::user::profile::UpdateProfileParams, responses( (status = 200, description = "Update current user profile", body = ApiResponse), (status = 401, description = "Unauthorized"), ), tag = "User" )] pub async fn update_my_profile( service: web::Data, session: Session, body: web::Json, ) -> Result { let resp = service .user_update_profile(&session, body.into_inner()) .await?; Ok(ApiResponse::ok(resp).to_response()) }