feat: Add optional display name to user profile with corresponding API and UI updates
This commit is contained in:
@@ -28,6 +28,7 @@ pub struct CreateUserRequest {
|
||||
/// Request to update a user.
|
||||
#[derive(Deserialize)]
|
||||
pub struct UpdateUserRequest {
|
||||
pub name: Option<String>,
|
||||
pub height_cm: Option<f32>,
|
||||
pub blood_type: Option<String>,
|
||||
pub birthdate: Option<String>,
|
||||
@@ -41,6 +42,7 @@ pub struct UpdateUserRequest {
|
||||
pub struct UserResponse {
|
||||
pub id: i32,
|
||||
pub username: String,
|
||||
pub name: Option<String>,
|
||||
pub role: String,
|
||||
pub height_cm: Option<f32>,
|
||||
pub blood_type: Option<String>,
|
||||
@@ -85,6 +87,7 @@ pub async fn list_users(
|
||||
.map(|u| UserResponse {
|
||||
id: u.id,
|
||||
username: u.username,
|
||||
name: u.name,
|
||||
role: role_map.get(&u.role_id).cloned().unwrap_or_default(),
|
||||
height_cm: u.height_cm,
|
||||
blood_type: u.blood_type,
|
||||
@@ -130,6 +133,7 @@ pub async fn get_user(
|
||||
Ok(Json(UserResponse {
|
||||
id: u.id,
|
||||
username: u.username,
|
||||
name: u.name,
|
||||
role: role_name,
|
||||
height_cm: u.height_cm,
|
||||
blood_type: u.blood_type,
|
||||
@@ -211,6 +215,7 @@ pub async fn create_user(
|
||||
Ok(Json(UserResponse {
|
||||
id: inserted.id,
|
||||
username: inserted.username,
|
||||
name: inserted.name,
|
||||
role: role_name,
|
||||
height_cm: inserted.height_cm,
|
||||
blood_type: inserted.blood_type,
|
||||
@@ -246,6 +251,9 @@ pub async fn update_user(
|
||||
let now = Utc::now().naive_utc();
|
||||
|
||||
let mut active: user::ActiveModel = existing.into();
|
||||
if req.name.is_some() {
|
||||
active.name = Set(req.name);
|
||||
}
|
||||
if req.height_cm.is_some() {
|
||||
active.height_cm = Set(req.height_cm);
|
||||
}
|
||||
@@ -291,6 +299,7 @@ pub async fn update_user(
|
||||
Ok(Json(UserResponse {
|
||||
id: updated.id,
|
||||
username: updated.username,
|
||||
name: updated.name,
|
||||
role: role_name,
|
||||
height_cm: updated.height_cm,
|
||||
blood_type: updated.blood_type,
|
||||
|
||||
@@ -18,6 +18,9 @@ pub struct Model {
|
||||
/// Foreign key to roles table
|
||||
pub role_id: i32,
|
||||
|
||||
/// Display name (optional, separate from username)
|
||||
pub name: Option<String>,
|
||||
|
||||
// Profile fields
|
||||
/// Height in centimeters
|
||||
pub height_cm: Option<f32>,
|
||||
|
||||
Reference in New Issue
Block a user