4028f0d943
- Reordered actix-web imports to standardize import order - Reordered crate module imports to follow alphabetical ordering - Updated function calls to use multi-line formatting for better readability - Standardized blank lines around documentation comments - Applied consistent formatting to response handling methods - Normalized import organization across all repository-related API files - Improved code consistency and maintainability through standardized formatting - Applied formatting updates to all repository endpoint implementations
57 lines
2.1 KiB
Rust
57 lines
2.1 KiB
Rust
use actix_web::{HttpResponse, web};
|
|
|
|
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
|
use crate::error::AppError;
|
|
use crate::service::AppService;
|
|
use crate::service::user::account::{UploadUserAvatarParams, UserAvatarResponse};
|
|
use crate::session::Session;
|
|
|
|
/// Upload user avatar
|
|
///
|
|
/// Uploads a new avatar image for the authenticated user.
|
|
/// Requires authentication.
|
|
///
|
|
/// Parameters:
|
|
/// - data: Raw avatar image bytes (PNG, JPEG, or WebP, max 5MB)
|
|
/// - content_type: MIME type of the image (e.g., "image/png")
|
|
/// - file_name: Original file name (used to infer file extension)
|
|
///
|
|
/// Effects:
|
|
/// - Avatar image is stored in S3-compatible object storage
|
|
/// - Previous avatar is deleted from storage
|
|
/// - User's avatar URL is updated
|
|
///
|
|
/// Returns the new avatar URL and storage key.
|
|
#[utoipa::path(
|
|
post,
|
|
path = "/api/v1/user/account/avatar",
|
|
tag = "User",
|
|
operation_id = "userUploadAvatar",
|
|
request_body(
|
|
content = UploadUserAvatarParams,
|
|
description = "Avatar upload parameters",
|
|
content_type = "application/json"
|
|
),
|
|
responses(
|
|
(status = 200, description = "Avatar uploaded successfully. Returns the new avatar URL and storage key.", body = ApiResponse<UserAvatarResponse>),
|
|
(status = 400, description = "Invalid parameters: unsupported file type or image too large", body = ApiErrorResponse),
|
|
(status = 401, description = "Authentication required or session expired", body = ApiErrorResponse),
|
|
(status = 404, description = "User not found", body = ApiErrorResponse),
|
|
(status = 500, description = "Internal server error or S3 storage failure", body = ApiErrorResponse),
|
|
),
|
|
security(
|
|
("session_cookie" = [])
|
|
)
|
|
)]
|
|
pub async fn upload_avatar(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
params: web::Json<UploadUserAvatarParams>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let response = service
|
|
.user
|
|
.user_upload_avatar(&session, params.into_inner())
|
|
.await?;
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(response)))
|
|
}
|