init
This commit is contained in:
@@ -10,11 +10,14 @@ use crate::error::{AppError, AppResult};
|
||||
use crate::models::UserSettings;
|
||||
use crate::state::AppState;
|
||||
|
||||
mod lists;
|
||||
|
||||
pub fn router() -> Router<AppState> {
|
||||
Router::new()
|
||||
.route("/health", get(health))
|
||||
.route("/settings", patch(update_settings))
|
||||
.route("/profile", patch(update_profile))
|
||||
.merge(lists::router())
|
||||
}
|
||||
|
||||
async fn health() -> Json<Value> {
|
||||
@@ -50,7 +53,9 @@ async fn update_settings(
|
||||
}
|
||||
if let Some(cur) = &req.currency {
|
||||
if cur.len() != 3 {
|
||||
return Err(AppError::Validation("currency must be a 3-letter code".into()));
|
||||
return Err(AppError::Validation(
|
||||
"currency must be a 3-letter code".into(),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +93,11 @@ async fn update_profile(
|
||||
req.validate()
|
||||
.map_err(|e| AppError::Validation(e.to_string()))?;
|
||||
|
||||
let display = req.display_name.as_deref().map(str::trim).filter(|s| !s.is_empty());
|
||||
let display = req
|
||||
.display_name
|
||||
.as_deref()
|
||||
.map(str::trim)
|
||||
.filter(|s| !s.is_empty());
|
||||
sqlx::query("UPDATE users SET display_name = $2 WHERE id = $1")
|
||||
.bind(user.id)
|
||||
.bind(display)
|
||||
|
||||
Reference in New Issue
Block a user