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), (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, session: Session, params: web::Json, ) -> Result { let settings = service .user .user_update_notify_setting(&session, params.into_inner()) .await?; Ok(HttpResponse::Ok().json(ApiResponse::new(settings))) }