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.2 KiB
Rust
57 lines
2.2 KiB
Rust
use actix_web::{HttpResponse, web};
|
|
|
|
use crate::api::response::{ApiErrorResponse, ApiResponse};
|
|
use crate::error::AppError;
|
|
use crate::models::users::UserNotifySetting;
|
|
use crate::service::AppService;
|
|
use crate::service::user::notify::UpdateUserNotifySettingParams;
|
|
use crate::session::Session;
|
|
|
|
/// Update user notification settings
|
|
///
|
|
/// Updates the authenticated user's notification preferences.
|
|
/// Requires authentication.
|
|
///
|
|
/// Updatable fields:
|
|
/// - email_notifications: Enable/disable email notifications
|
|
/// - web_notifications: Enable/disable web push notifications
|
|
/// - mention_notifications: Enable/disable @mention notifications
|
|
/// - review_notifications: Enable/disable code review notifications
|
|
/// - security_notifications: Enable/disable security notifications
|
|
/// - marketing_emails: Enable/disable marketing emails
|
|
/// - digest_frequency: Digest email frequency ("realtime", "daily", "weekly", "off")
|
|
///
|
|
/// All fields are optional; only provided fields are updated.
|
|
/// Returns the updated notification settings.
|
|
#[utoipa::path(
|
|
put,
|
|
path = "/api/v1/user/notifications",
|
|
tag = "User",
|
|
operation_id = "userUpdateNotifications",
|
|
request_body(
|
|
content = UpdateUserNotifySettingParams,
|
|
description = "Notification settings update parameters (all fields optional)",
|
|
content_type = "application/json"
|
|
),
|
|
responses(
|
|
(status = 200, description = "Notification settings updated successfully. Returns all updated preferences.", body = ApiResponse<UserNotifySetting>),
|
|
(status = 400, description = "Invalid parameters: unsupported digest frequency", 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_notifications(
|
|
service: web::Data<AppService>,
|
|
session: Session,
|
|
params: web::Json<UpdateUserNotifySettingParams>,
|
|
) -> Result<HttpResponse, AppError> {
|
|
let settings = service
|
|
.user
|
|
.user_update_notify_setting(&session, params.into_inner())
|
|
.await?;
|
|
Ok(HttpResponse::Ok().json(ApiResponse::new(settings)))
|
|
}
|