2025-03-23 12:32:00 +07:00
|
|
|
use lazy_static::lazy_static;
|
|
|
|
|
use regex::Regex;
|
2025-02-26 15:45:05 +07:00
|
|
|
use serde::{Deserialize, Serialize};
|
2025-03-26 13:06:34 +07:00
|
|
|
use surrealdb::sql::Thing;
|
2025-02-26 15:45:05 +07:00
|
|
|
use utoipa::ToSchema;
|
2025-03-23 12:32:00 +07:00
|
|
|
use validator::Validate;
|
2025-02-26 15:45:05 +07:00
|
|
|
|
2025-03-26 13:06:34 +07:00
|
|
|
use crate::RolesItemDto;
|
|
|
|
|
|
2025-03-23 12:32:00 +07:00
|
|
|
lazy_static! {
|
|
|
|
|
static ref PASSWORD_REGEX: Regex = Regex::new(r"^[A-Za-z\d@$!%*?&]{8,}$").unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
2025-03-20 22:41:20 +07:00
|
|
|
pub struct UsersCreateRequestDto {
|
2025-03-23 12:32:00 +07:00
|
|
|
#[validate(
|
|
|
|
|
length(min = 1, message = "Email cannot be empty"),
|
|
|
|
|
email(message = "Email not valid")
|
|
|
|
|
)]
|
2025-03-20 22:41:20 +07:00
|
|
|
pub email: String,
|
2025-03-23 12:32:00 +07:00
|
|
|
#[validate(length(
|
|
|
|
|
min = 8,
|
|
|
|
|
message = "Password must have at least 8 characters"
|
|
|
|
|
))]
|
|
|
|
|
#[validate(regex(
|
|
|
|
|
path = "PASSWORD_REGEX",
|
|
|
|
|
message = "Password must include uppercase, lowercase, number, and special character"
|
|
|
|
|
))]
|
2025-03-20 22:41:20 +07:00
|
|
|
pub password: String,
|
2025-03-23 12:32:00 +07:00
|
|
|
#[validate(length(min = 2, message = "Fullname at least have 2 character"))]
|
|
|
|
|
pub fullname: String,
|
|
|
|
|
#[validate(length(min = 1, message = "Student type is required"))]
|
|
|
|
|
pub student_type: String,
|
|
|
|
|
#[validate(length(
|
|
|
|
|
min = 10,
|
|
|
|
|
message = "Phone number at least have 10 character"
|
|
|
|
|
))]
|
|
|
|
|
pub phone_number: String,
|
|
|
|
|
#[validate(length(
|
|
|
|
|
max = 4,
|
|
|
|
|
message = "Referal code cannot be more than 4 character"
|
|
|
|
|
))]
|
|
|
|
|
pub referral_code: Option<String>,
|
|
|
|
|
pub referred_by: Option<String>,
|
|
|
|
|
pub is_active: bool,
|
2025-03-23 20:42:38 +07:00
|
|
|
pub role_id: String,
|
2025-03-23 12:32:00 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
|
|
|
|
|
pub struct UsersUpdateRequestDto {
|
|
|
|
|
#[validate(
|
|
|
|
|
length(min = 1, message = "Email cannot be empty"),
|
|
|
|
|
email(message = "Email not valid")
|
|
|
|
|
)]
|
|
|
|
|
pub email: String,
|
|
|
|
|
#[validate(length(
|
|
|
|
|
min = 8,
|
|
|
|
|
message = "Password must have at least 8 characters"
|
|
|
|
|
))]
|
|
|
|
|
#[validate(length(min = 2, message = "Fullname at least have 2 character"))]
|
|
|
|
|
pub fullname: String,
|
|
|
|
|
#[validate(length(min = 1, message = "Student type is required"))]
|
|
|
|
|
pub student_type: String,
|
|
|
|
|
#[validate(length(
|
|
|
|
|
min = 10,
|
|
|
|
|
message = "Phone number at least have 10 character"
|
|
|
|
|
))]
|
|
|
|
|
pub phone_number: String,
|
|
|
|
|
#[validate(length(
|
|
|
|
|
max = 4,
|
|
|
|
|
message = "Referal code cannot be more than 4 character"
|
|
|
|
|
))]
|
|
|
|
|
pub referral_code: Option<String>,
|
|
|
|
|
pub referred_by: Option<String>,
|
|
|
|
|
pub is_active: bool,
|
|
|
|
|
#[validate(length(min = 16, message = "NIK at must have 16 character"))]
|
|
|
|
|
pub identity_number: Option<String>,
|
|
|
|
|
pub religion: Option<String>,
|
|
|
|
|
pub gender: Option<String>,
|
|
|
|
|
pub birthdate: Option<String>,
|
|
|
|
|
pub avatar: Option<String>,
|
2025-03-23 20:42:38 +07:00
|
|
|
pub role_id: String,
|
2025-03-20 22:41:20 +07:00
|
|
|
}
|
|
|
|
|
|
2025-02-26 15:45:05 +07:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
|
|
|
|
pub struct UsersItemDto {
|
2025-03-23 07:56:43 +07:00
|
|
|
pub id: String,
|
2025-03-26 13:06:34 +07:00
|
|
|
pub role: RolesItemDto,
|
2025-02-26 15:45:05 +07:00
|
|
|
pub fullname: String,
|
2025-03-23 07:56:43 +07:00
|
|
|
pub email: String,
|
|
|
|
|
pub avatar: Option<String>,
|
|
|
|
|
pub phone_number: String,
|
|
|
|
|
pub referred_by: Option<String>,
|
2025-03-23 12:32:00 +07:00
|
|
|
pub referral_code: Option<String>,
|
2025-03-23 07:56:43 +07:00
|
|
|
pub student_type: String,
|
2025-03-23 12:32:00 +07:00
|
|
|
pub is_active: bool,
|
|
|
|
|
pub is_profile_completed: bool,
|
|
|
|
|
pub identity_number: Option<String>,
|
2025-03-23 07:56:43 +07:00
|
|
|
pub religion: Option<String>,
|
|
|
|
|
pub gender: Option<String>,
|
|
|
|
|
pub birthdate: Option<String>,
|
2025-03-23 12:32:00 +07:00
|
|
|
}
|
|
|
|
|
|
2025-03-26 13:06:34 +07:00
|
|
|
#[derive(Debug, Serialize, Deserialize)]
|
|
|
|
|
pub struct UsersItemDtoRaw {
|
|
|
|
|
pub id: Thing,
|
|
|
|
|
pub role: Thing,
|
|
|
|
|
pub fullname: String,
|
|
|
|
|
pub email: String,
|
|
|
|
|
pub avatar: Option<String>,
|
|
|
|
|
pub phone_number: String,
|
|
|
|
|
pub referred_by: Option<String>,
|
|
|
|
|
pub referral_code: Option<String>,
|
|
|
|
|
pub student_type: String,
|
|
|
|
|
pub is_active: bool,
|
|
|
|
|
pub is_profile_completed: bool,
|
|
|
|
|
pub identity_number: Option<String>,
|
|
|
|
|
pub religion: Option<String>,
|
|
|
|
|
pub gender: Option<String>,
|
|
|
|
|
pub birthdate: Option<String>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl From<UsersItemDtoRaw> for UsersItemDto {
|
|
|
|
|
fn from(raw: UsersItemDtoRaw) -> Self {
|
|
|
|
|
Self {
|
|
|
|
|
id: raw.id.id.to_string(),
|
|
|
|
|
role: RolesItemDto {
|
|
|
|
|
id: raw.role.id.to_string(),
|
|
|
|
|
name: "".into(),
|
|
|
|
|
is_deleted: false,
|
|
|
|
|
permissions: vec![],
|
|
|
|
|
created_at: None,
|
|
|
|
|
updated_at: None,
|
|
|
|
|
},
|
|
|
|
|
fullname: raw.fullname,
|
|
|
|
|
email: raw.email,
|
|
|
|
|
avatar: raw.avatar,
|
|
|
|
|
phone_number: raw.phone_number,
|
|
|
|
|
referred_by: raw.referred_by,
|
|
|
|
|
referral_code: raw.referral_code,
|
|
|
|
|
student_type: raw.student_type,
|
|
|
|
|
is_active: raw.is_active,
|
|
|
|
|
is_profile_completed: raw.is_profile_completed,
|
|
|
|
|
identity_number: raw.identity_number,
|
|
|
|
|
religion: raw.religion,
|
|
|
|
|
gender: raw.gender,
|
|
|
|
|
birthdate: raw.birthdate,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-23 12:32:00 +07:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
|
|
|
|
|
pub struct UsersActiveInactiveRequestDto {
|
|
|
|
|
pub is_active: bool,
|
2025-02-26 15:45:05 +07:00
|
|
|
}
|