feat: add profile avatar selection and enhance sidebar UI with icons

This commit is contained in:
2025-12-20 12:26:28 +05:30
parent e558e19512
commit 69bc5675dc
28 changed files with 166 additions and 15 deletions

View File

@@ -35,6 +35,7 @@ pub struct UpdateUserRequest {
pub smoking: Option<bool>,
pub alcohol: Option<bool>,
pub diet_id: Option<i32>,
pub avatar_url: Option<String>,
}
/// Response for a user.
@@ -50,6 +51,7 @@ pub struct UserResponse {
pub smoking: Option<bool>,
pub alcohol: Option<bool>,
pub diet: Option<String>,
pub avatar_url: Option<String>,
pub created_at: String,
}
@@ -95,6 +97,7 @@ pub async fn list_users(
smoking: u.smoking,
alcohol: u.alcohol,
diet: u.diet_id.and_then(|id| diet_map.get(&id).cloned()),
avatar_url: u.avatar_url,
created_at: u.created_at.to_string(),
})
.collect();
@@ -141,6 +144,7 @@ pub async fn get_user(
smoking: u.smoking,
alcohol: u.alcohol,
diet: diet_name,
avatar_url: u.avatar_url,
created_at: u.created_at.to_string(),
}))
}
@@ -188,6 +192,7 @@ pub async fn create_user(
smoking: Set(req.smoking),
alcohol: Set(req.alcohol),
diet_id: Set(req.diet_id),
avatar_url: Set(None), // Default to None on create for now, unless we want to support it in CreateUserRequest
created_at: Set(now),
updated_at: Set(now),
..Default::default()
@@ -223,6 +228,7 @@ pub async fn create_user(
smoking: inserted.smoking,
alcohol: inserted.alcohol,
diet: diet_name,
avatar_url: inserted.avatar_url,
created_at: inserted.created_at.to_string(),
}))
}
@@ -270,6 +276,9 @@ pub async fn update_user(
if req.diet_id.is_some() {
active.diet_id = Set(req.diet_id);
}
if req.avatar_url.is_some() {
active.avatar_url = Set(req.avatar_url);
}
active.updated_at = Set(now);
let updated = active
@@ -307,6 +316,7 @@ pub async fn update_user(
smoking: updated.smoking,
alcohol: updated.alcohol,
diet: diet_name,
avatar_url: updated.avatar_url,
created_at: updated.created_at.to_string(),
}))
}

View File

@@ -41,6 +41,9 @@ pub struct Model {
/// Foreign key to diet types
pub diet_id: Option<i32>,
/// URL to profile avatar icon
pub avatar_url: Option<String>,
pub created_at: DateTime,
pub updated_at: DateTime,
}