//! Settings handlers. //! //! - `GET /api/v1/settings` — returns the current user's settings //! - `PUT /api/v1/settings` — updates the current user's settings use axum::extract::State; use axum::response::IntoResponse; use axum::Json; use crate::app_state::AppState; use crate::db; use crate::errors::AppError; use crate::middleware::auth::AuthUser; use crate::models::settings::UpdateSettingsRequest; /// `GET /api/v1/settings` /// /// Returns the authenticated user's settings. Creates default settings /// on first access if none exist. pub async fn get_settings( auth_user: AuthUser, State(state): State, ) -> Result { let settings = db::settings::get_or_create_default(&state.pool, auth_user.id).await?; Ok(Json(settings)) } /// `PUT /api/v1/settings` /// /// Updates the authenticated user's settings. Validates all fields /// before persisting. pub async fn update_settings( auth_user: AuthUser, State(state): State, Json(body): Json, ) -> Result { body.validate().map_err(AppError::Validation)?; let settings = db::settings::upsert(&state.pool, auth_user.id, &body).await?; tracing::info!(user_id = %auth_user.id, "Settings updated"); Ok(Json(settings)) }