Refactor permissions and user DTOs to use imphnen_entities module
- Updated permissions_repository.rs to import PermissionsItemDto from imphnen_entities. - Modified permissions_schema.rs to import PermissionsItemDto and PermissionsQueryDto from imphnen_entities. - Changed roles_dto.rs to import PermissionsItemDto and PermissionsQueryDto from imphnen_entities. - Updated users_dto.rs to import ExperienceDto, EducationDto, UsersDetailQueryDto, RolesDetailQueryDto, and RolesDetailItemDto from imphnen_entities, and removed redundant struct definitions. - Refactored users_repository.rs to import UsersDetailQueryDto from imphnen_entities. - Updated users_schema.rs to import UsersDetailQueryDto, ExperienceDto, and EducationDto from imphnen_entities. - Modified users_service.rs to use UsersDetailQueryDto from imphnen_entities and added UserLookupService implementation. - Updated Cargo.toml in imphnen-libs to include async-trait as a workspace dependency. - Refactored axum module to remove redundant imports and streamline code. - Updated lib.rs to include AppState struct with user_lookup_service and auth_repository fields. - Refactored surrealdb module to define SurrealWsClient and SurrealMemClient types. - Removed imphnen-iam dependency from middleware's Cargo.toml. - Updated auth_middleware to use UsersDetailQueryDto from imphnen_entities and refactored user retrieval logic. - Refactored permissions_middleware to use PermissionsEnum from imphnen_entities and updated user retrieval logic. - Updated mock_test.rs to create AppState with user_lookup_service and auth_repository. - Added permissions.rs and users.rs to imphnen_entities with necessary DTOs and enums. - Created services.rs in imphnen-libs to define UserLookupService and AuthRepositoryTrait traits.
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
use crate::{surrealdb_init_mem, surrealdb_init_ws};
|
||||
use crate::{surrealdb_init_mem, surrealdb_init_ws, SurrealMemClient, SurrealWsClient};
|
||||
use axum::{Router, serve};
|
||||
use imphnen_entities::{SurrealMemClient, SurrealWsClient};
|
||||
use std::{future::Future, net::SocketAddr};
|
||||
use tokio::net::TcpListener;
|
||||
use crate::enviroment::ENV;
|
||||
|
||||
+11
-1
@@ -1,4 +1,4 @@
|
||||
use imphnen_entities::*;
|
||||
use std::sync::Arc;
|
||||
|
||||
pub mod argon;
|
||||
pub mod axum;
|
||||
@@ -6,6 +6,7 @@ pub mod enviroment;
|
||||
pub mod jsonwebtoken;
|
||||
pub mod lettre;
|
||||
pub mod minio;
|
||||
pub mod services;
|
||||
pub mod surrealdb;
|
||||
|
||||
pub use argon::*;
|
||||
@@ -15,4 +16,13 @@ pub use imphnen_entities::*;
|
||||
pub use jsonwebtoken::*;
|
||||
pub use lettre::*;
|
||||
pub use minio::*;
|
||||
pub use services::*;
|
||||
pub use surrealdb::*;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct AppState {
|
||||
pub surrealdb_ws: SurrealWsClient,
|
||||
pub surrealdb_mem: SurrealMemClient,
|
||||
pub user_lookup_service: Arc<dyn UserLookupService>,
|
||||
pub auth_repository: Arc<dyn AuthRepositoryTrait>,
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
use async_trait::async_trait;
|
||||
use imphnen_entities::UsersDetailQueryDto;
|
||||
use crate::AppState;
|
||||
use std::result::Result;
|
||||
use surrealdb::sql::Thing;
|
||||
|
||||
#[async_trait]
|
||||
pub trait UserLookupService: Send + Sync {
|
||||
async fn get_user_by_id_internal(
|
||||
&self,
|
||||
thing_id: &Thing,
|
||||
state: &AppState,
|
||||
) -> Result<UsersDetailQueryDto, anyhow::Error>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait AuthRepositoryTrait: Send + Sync {
|
||||
async fn query_get_stored_user(
|
||||
&self,
|
||||
email: String,
|
||||
) -> Result<UsersDetailQueryDto, anyhow::Error>;
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
use crate::enviroment::ENV;
|
||||
use crate::SurrealMemClient;
|
||||
use surrealdb::engine::any;
|
||||
use surrealdb::engine::local::Mem;
|
||||
use surrealdb::engine::local::{Db, Mem};
|
||||
use surrealdb::opt::auth::Root;
|
||||
use surrealdb::{Result, Surreal};
|
||||
|
||||
pub type SurrealWsClient = Surreal<any::Any>;
|
||||
pub type SurrealMemClient = Surreal<Db>;
|
||||
|
||||
pub mod resource;
|
||||
pub use resource::*;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user