Files
imphnen-backend-service/imphnen-iam/src/v1/roles/roles_dto.rs
T
MythEclipse 1a2e0c58b6 Add comprehensive tests for mentor repository and authentication
- Implemented tests for creating, retrieving, updating, and deleting mentors in `mentor_repository_test.rs`.
- Added tests for user authentication, including successful login, invalid email formats, and inactive users in `auth_login_tests.rs`.
- Created a mock test environment setup in `mock_test.rs` to facilitate database operations during tests.
- Updated module structure to include new test files for mentors and authentication.
- Ensured cleanup of the database after tests to maintain isolation and prevent side effects.
2025-07-21 21:29:04 +07:00

80 lines
2.0 KiB
Rust

use crate::{PermissionsItemDto, PermissionsQueryDto};
use serde::{Deserialize, Serialize};
use surrealdb::sql::Thing;
use utoipa::ToSchema;
use validator::Validate;
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
pub struct RolesRequestUpdateDto {
#[validate(length(min = 1, message = "Role name must not be empty"))]
pub name: Option<String>,
pub permissions: Option<Vec<String>>,
pub overwrite: Option<bool>,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema, Validate)]
pub struct RolesRequestCreateDto {
#[validate(length(min = 1, message = "Role name must not be empty"))]
pub name: String,
pub permissions: Vec<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct RolesListItemDto {
pub id: String,
pub name: String,
pub permissions_count: usize,
pub created_at: Option<String>,
pub updated_at: Option<String>,
}
#[derive(Clone, Debug, Serialize, Deserialize, ToSchema)]
pub struct RolesDetailItemDto {
pub id: String,
pub name: String,
pub is_deleted: bool,
pub permissions: Vec<PermissionsItemDto>,
pub created_at: Option<String>,
pub updated_at: Option<String>,
}
impl RolesDetailItemDto {
pub fn from(dto: &RolesDetailQueryDto) -> Self {
Self {
id: dto.id.id.to_raw(),
name: dto.name.clone(),
is_deleted: dto.is_deleted,
permissions: dto
.permissions
.iter()
.map(PermissionsItemDto::from)
.collect(),
created_at: dto.created_at.clone(),
updated_at: dto.updated_at.clone(),
}
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct RolesDetailQueryDto {
pub id: Thing,
pub name: String,
pub permissions: Vec<PermissionsQueryDto>,
pub is_deleted: bool,
pub created_at: Option<String>,
pub updated_at: Option<String>,
}
impl Default for RolesDetailQueryDto {
fn default() -> Self {
Self {
id: Thing::from(("".to_string(), surrealdb::sql::Id::Number(0))),
name: String::new(),
permissions: Vec::new(),
is_deleted: false,
created_at: None,
updated_at: None,
}
}
}