Files
imphnen-backend-service/src/apps/v1/users/users_dto.rs
T

104 lines
2.9 KiB
Rust
Raw Normal View History

use lazy_static::lazy_static;
use regex::Regex;
2025-02-26 15:45:05 +07:00
use serde::{Deserialize, Serialize};
use utoipa::ToSchema;
use validator::Validate;
2025-02-26 15:45:05 +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 {
#[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,
#[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,
#[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,
}
#[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-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>,
pub referral_code: Option<String>,
2025-03-23 07:56:43 +07:00
pub student_type: String,
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>,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct UsersActiveInactiveRequestDto {
pub is_active: bool,
2025-02-26 15:45:05 +07:00
}