chore: normalize code #2

This commit is contained in:
Maulana Sodiqin
2025-05-18 03:12:20 +07:00
parent a43ef8ec04
commit e48507901e
15 changed files with 603 additions and 365 deletions
+32 -3
View File
@@ -1,4 +1,4 @@
use crate::{RolesDetailQueryDto, RolesItemDto};
use crate::{RolesDetailItemDto, RolesDetailQueryDto};
use lazy_static::lazy_static;
use regex::Regex;
use serde::{Deserialize, Serialize};
@@ -10,6 +10,17 @@ lazy_static! {
static ref PASSWORD_REGEX: Regex = Regex::new(r"^[A-Za-z\d@$!%*?&]{8,}$").unwrap();
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersActiveInactiveRequestDto {
pub is_active: bool,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersSetNewPasswordRequestDto {
pub password: String,
pub old_password: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
pub struct UsersCreateRequestDto {
#[validate(
@@ -71,7 +82,7 @@ pub struct UsersUpdateRequestDto {
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersDetailItemDto {
pub id: String,
pub role: RolesItemDto,
pub role: RolesDetailItemDto,
pub fullname: String,
pub email: String,
pub avatar: Option<String>,
@@ -83,6 +94,24 @@ pub struct UsersDetailItemDto {
pub updated_at: String,
}
impl UsersDetailItemDto {
pub fn from(dto: UsersDetailQueryDto) -> Self {
Self {
id: dto.id.id.to_raw(),
role: RolesDetailItemDto::from(&dto.role),
fullname: dto.fullname,
email: dto.email,
avatar: dto.avatar,
phone_number: dto.phone_number,
is_active: dto.is_active,
gender: dto.gender,
birthdate: dto.birthdate,
created_at: dto.created_at,
updated_at: dto.updated_at,
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersListItemDto {
pub id: String,
@@ -110,7 +139,7 @@ pub struct UsersListQueryDto {
}
impl UsersListQueryDto {
pub fn list_from(&self, role: String) -> UsersListItemDto {
pub fn from(&self, role: String) -> UsersListItemDto {
UsersListItemDto {
id: self.id.id.to_raw(),
role,