Refactor and enhance SurrealDB integration and resource management

- Updated `lib.rs` to selectively expose specific entities and services for better clarity.
- Improved SurrealDB client initialization with detailed logging in `surrealdb/mod.rs`.
- Enhanced resource definitions in `resource.rs` with additional utility methods for better resource management.
- Refactored user data retrieval logic in `auth_middleware/mod.rs` for improved readability and efficiency.
- Cleaned up middleware exports in `lib.rs` for clearer API surface.
- Added detailed comments and documentation throughout the SurrealDB module for better maintainability.
- Updated tests to ensure compatibility with new changes and improved structure.
- Introduced new permissions module structure in `imphnen-utils` for future enhancements.
This commit is contained in:
MythEclipse
2025-09-26 17:35:30 +07:00
parent 96debc210a
commit 14b22328de
71 changed files with 1566 additions and 632 deletions
+4 -1
View File
@@ -1,2 +1,5 @@
pub mod v1;
pub use v1::*;
// Explicitly export only what's needed from v1
pub use v1::dimentorin_router;
pub use v1::mentors::mentors_router;
@@ -167,7 +167,7 @@ pub struct MentorUserRegisterRequestDto {
message = "Password must have at least 8 characters"
))]
#[validate(custom(
function = "imphnen_iam::auth_dto::validate_password_complexity",
function = "imphnen_iam::v1::auth::auth_dto::validate_password_complexity",
message = "Password must include uppercase, lowercase, number, and special character"
))]
pub password: String,
@@ -2,7 +2,8 @@ use anyhow::{Result, bail};
use imphnen_iam::{get_id, make_thing};
use surrealdb::sql::Thing;
use crate::v1::mentors::{MentorDetailWithUserDto, MentorInsertDto, MentorSchema};
use crate::v1::mentors::mentors_dto::MentorDetailWithUserDto;
use crate::v1::mentors::{MentorInsertDto, MentorSchema};
use imphnen_libs::{AppState, MetaRequestDto, ResourceEnum, ResponseListSuccessDto};
use imphnen_utils::{DetailQueryBuilder, QueryListBuilder, get_iso_date};
use serde_json::{Map, Value};
+36 -5
View File
@@ -9,11 +9,42 @@ pub mod mentors_repository;
pub mod mentors_schema;
pub mod mentors_service;
pub use mentors_controller::*;
pub use mentors_dto::*;
pub use mentors_repository::*;
pub use mentors_schema::*;
pub use mentors_service::*;
// Explicitly export only public controller functions and key types
pub use mentors_controller::{
post_register_mentor,
get_mentor_list,
get_mentor_by_id,
put_update_mentor,
delete_mentor,
put_verify_mentor,
get_mentor_me,
put_update_mentor_me,
put_update_mentor_no_id,
get_mentor_status,
};
// Export key DTO types used across the API
pub use mentors_dto::{
MentorListResponseDto,
MentorDetailResponseDto,
MentorRegisterResponseDto,
MentorUpdateRequestDto,
MentorUserRegisterRequestDto,
MentorVerifyRequestDto,
MentorDetailQueryDto,
ProfessionalProfile,
MentoringLogistics,
MentoringRate,
IdentityAndVerification,
MentorInsertDto,
};
// Export service and repository for internal use
pub use mentors_service::MentorsService;
pub use mentors_repository::MentorsRepository;
// Export schema types for database interactions
pub use mentors_schema::MentorSchema;
pub fn mentors_router() -> Router {
Router::new()
+11 -1
View File
@@ -2,6 +2,16 @@ use axum::Router;
pub mod mentors;
/// Creates the main Dimentorin router with all version 1 endpoints
/// Routes:
/// - /mentors -> mentors::mentors_router()
pub fn dimentorin_router() -> Router {
Router::new().nest("/mentors", mentors::mentors_router())
Router::new()
.nest("/mentors", mentors::mentors_router())
}
// Explicitly re-export key items for easier consumption
pub use mentors::mentors_router;
pub use mentors::MentorsService;
pub use mentors::MentorsRepository;
pub use mentors::MentorSchema;
+13
View File
@@ -1 +1,14 @@
/// Version 2 of the Dimentorin API - currently under development
/// This module will contain all version 2 endpoints following API versioning best practices
use axum::Router;
/// Placeholder for version 2 router
/// To be implemented when version 2 endpoints are ready
pub fn dimentorin_v2_router() -> Router {
Router::new()
// Version 2 endpoints will be added here following the same pattern as v1
}
// Re-export the v1 router for backward compatibility
pub use crate::v1::dimentorin_router;