feat(users): Add optional fields to user schemas and update user avatar functionality

This commit is contained in:
MythEclipse
2025-08-12 17:31:12 +07:00
parent a25e896fa2
commit 34b6cdabfb
13 changed files with 297 additions and 5 deletions
+77
View File
@@ -67,16 +67,33 @@ pub struct UsersUpdateRequestDto {
pub password: String,
#[validate(length(min = 2, message = "Fullname at least have 2 character"))]
pub fullname: String,
#[validate(length(min = 2, message = "Legal name at least have 2 character"))]
pub legal_name: Option<String>,
#[validate(length(
min = 10,
message = "Phone number at least have 10 character"
))]
pub phone_number: String,
pub phone_for_verification: Option<String>,
pub is_active: bool,
#[validate(length(min = 1, message = "Gender is required"))]
pub gender: Option<String>,
#[validate(length(min = 1, message = "Birthdate is required"))]
pub birthdate: Option<String>,
pub domicile: Option<String>,
#[validate(url(message = "Invalid identity document URL"))]
pub identity_document_url: Option<String>,
#[validate(length(min = 50, message = "Bio must be at least 50 characters"))]
pub bio: Option<String>,
pub last_education: Option<String>,
#[validate(url(message = "Invalid LinkedIn URL"))]
pub linkedin_url: Option<String>,
#[validate(url(message = "Invalid GitHub URL"))]
pub github_url: Option<String>,
#[validate(url(message = "Invalid CV URL"))]
pub cv_url: Option<String>,
#[validate(url(message = "Invalid portfolio URL"))]
pub portfolio_url: Option<String>,
#[validate(length(min = 1, message = "Avatar is required"))]
pub avatar: Option<String>,
pub role_id: String,
@@ -87,12 +104,22 @@ pub struct UsersDetailItemDto {
pub id: String,
pub role: RolesDetailItemDto,
pub fullname: String,
pub legal_name: Option<String>,
pub email: String,
pub avatar: Option<String>,
pub phone_number: String,
pub phone_for_verification: Option<String>,
pub is_active: bool,
pub gender: Option<String>,
pub birthdate: Option<String>,
pub domicile: Option<String>,
pub identity_document_url: Option<String>,
pub bio: Option<String>,
pub last_education: Option<String>,
pub linkedin_url: Option<String>,
pub github_url: Option<String>,
pub cv_url: Option<String>,
pub portfolio_url: Option<String>,
pub created_at: String,
pub updated_at: String,
}
@@ -103,12 +130,22 @@ impl UsersDetailItemDto {
id: dto.id.id.to_raw().clone(),
role: RolesDetailItemDto::from(&dto.role),
fullname: dto.fullname.clone(),
legal_name: dto.legal_name.clone(),
email: dto.email.clone(),
avatar: dto.avatar.clone(),
phone_number: dto.phone_number.clone(), // Corrected from dto.phone.clone()
phone_for_verification: dto.phone_for_verification.clone(),
is_active: dto.is_active,
gender: dto.gender.clone(),
birthdate: dto.birthdate.clone(),
domicile: dto.domicile.clone(),
identity_document_url: dto.identity_document_url.clone(),
bio: dto.bio.clone(),
last_education: dto.last_education.clone(),
linkedin_url: dto.linkedin_url.clone(),
github_url: dto.github_url.clone(),
cv_url: dto.cv_url.clone(),
portfolio_url: dto.portfolio_url.clone(),
created_at: dto.created_at.clone(),
updated_at: dto.updated_at.clone(),
}
@@ -119,12 +156,22 @@ impl UsersDetailItemDto {
id: schema.id.id.to_raw(),
role: RolesDetailItemDto::default(), // Placeholder, role needs to be fetched
fullname: schema.fullname.clone(),
legal_name: schema.legal_name.clone(),
email: schema.email.clone(),
avatar: schema.avatar.clone(),
phone_number: schema.phone_number.clone(),
phone_for_verification: schema.phone_for_verification.clone(),
is_active: schema.is_active,
gender: schema.gender.clone(),
birthdate: schema.birthdate.clone(),
domicile: schema.domicile.clone(),
identity_document_url: schema.identity_document_url.clone(),
bio: schema.bio.clone(),
last_education: schema.last_education.clone(),
linkedin_url: schema.linkedin_url.clone(),
github_url: schema.github_url.clone(),
cv_url: schema.cv_url.clone(),
portfolio_url: schema.portfolio_url.clone(),
created_at: schema.created_at.clone(),
updated_at: schema.updated_at.clone(),
}
@@ -177,13 +224,23 @@ impl UsersListQueryDto {
pub struct UsersDetailQueryDto {
pub id: Thing,
pub fullname: String,
pub legal_name: Option<String>,
pub email: String,
pub avatar: Option<String>,
pub phone_number: String,
pub phone_for_verification: Option<String>,
pub is_active: bool,
pub is_deleted: bool,
pub gender: Option<String>,
pub birthdate: Option<String>,
pub domicile: Option<String>,
pub identity_document_url: Option<String>,
pub bio: Option<String>,
pub last_education: Option<String>,
pub linkedin_url: Option<String>,
pub github_url: Option<String>,
pub cv_url: Option<String>,
pub portfolio_url: Option<String>,
pub password: String,
pub role: RolesDetailQueryDto,
pub created_at: String,
@@ -197,12 +254,22 @@ impl UsersDetailQueryDto {
id: self.id.clone(),
role: self.role.clone(),
fullname: self.fullname.clone(),
legal_name: self.legal_name.clone(),
email: self.email.clone(),
avatar: self.avatar.clone(),
phone_number: self.phone_number.clone(),
phone_for_verification: self.phone_for_verification.clone(),
is_active: self.is_active,
mentor_id: self.mentor_id.clone(),
gender: self.gender.clone(),
domicile: self.domicile.clone(),
identity_document_url: self.identity_document_url.clone(),
bio: self.bio.clone(),
last_education: self.last_education.clone(),
linkedin_url: self.linkedin_url.clone(),
github_url: self.github_url.clone(),
cv_url: self.cv_url.clone(),
portfolio_url: self.portfolio_url.clone(),
is_deleted: self.is_deleted,
password: self.password.clone(),
birthdate: self.birthdate.clone(),
@@ -217,13 +284,23 @@ impl From<&UsersDetailItemDto> for UsersDetailQueryDto {
Self {
id: crate::make_thing(&imphnen_libs::ResourceEnum::Users.to_string(), &dto.id),
fullname: dto.fullname.clone(),
legal_name: dto.legal_name.clone(),
email: dto.email.clone(),
avatar: dto.avatar.clone(),
phone_number: dto.phone_number.clone(),
phone_for_verification: dto.phone_for_verification.clone(),
is_active: dto.is_active,
is_deleted: false,
gender: dto.gender.clone(),
birthdate: dto.birthdate.clone(),
domicile: dto.domicile.clone(),
identity_document_url: dto.identity_document_url.clone(),
bio: dto.bio.clone(),
last_education: dto.last_education.clone(),
linkedin_url: dto.linkedin_url.clone(),
github_url: dto.github_url.clone(),
cv_url: dto.cv_url.clone(),
portfolio_url: dto.portfolio_url.clone(),
password: String::new(),
role: RolesDetailQueryDto::default(),
created_at: dto.created_at.clone(),