Add context reqruied later for authentication

This commit is contained in:
Simon Goller 2024-05-03 19:01:26 +02:00
parent 9a367c9260
commit 20828fb4a1
14 changed files with 463 additions and 330 deletions

View file

@ -1,6 +1,4 @@
use async_trait::async_trait;
use mockall::automock;
use std::{future::Future, sync::Arc};
use std::sync::Arc;
use thiserror::Error;
use time::Date;
use time::Time;
@ -9,6 +7,7 @@ use uuid::Uuid;
pub mod clock;
pub mod permission;
pub mod slot;
pub mod user_service;
pub mod uuid_service;
pub use permission::MockPermissionService;
@ -57,14 +56,3 @@ pub enum ServiceError {
#[error("Date order wrong. {0} must is not smaller or equal to {1}")]
DateOrderWrong(Date, Date),
}
#[automock]
pub trait HelloService {
fn hello(&self) -> impl Future<Output = Result<Arc<str>, ServiceError>> + Send;
}
#[automock]
#[async_trait]
pub trait UserService {
async fn current_user(&self) -> Result<Arc<str>, ServiceError>;
}

View file

@ -41,25 +41,62 @@ impl From<&dao::PrivilegeEntity> for Privilege {
}
}
#[automock]
#[automock(type Context=();)]
#[async_trait]
pub trait PermissionService {
async fn check_permission(&self, privilege: &str) -> Result<(), ServiceError>;
type Context: Clone + Send + Sync + 'static;
async fn create_user(&self, user: &str) -> Result<(), ServiceError>;
async fn delete_user(&self, user: &str) -> Result<(), ServiceError>;
async fn get_all_users(&self) -> Result<Arc<[User]>, ServiceError>;
async fn check_permission(
&self,
privilege: &str,
context: Self::Context,
) -> Result<(), ServiceError>;
async fn create_role(&self, role: &str) -> Result<(), ServiceError>;
async fn delete_role(&self, role: &str) -> Result<(), ServiceError>;
async fn get_all_roles(&self) -> Result<Arc<[Role]>, ServiceError>;
async fn create_user(&self, user: &str, context: Self::Context) -> Result<(), ServiceError>;
async fn delete_user(&self, user: &str, context: Self::Context) -> Result<(), ServiceError>;
async fn get_all_users(&self, context: Self::Context) -> Result<Arc<[User]>, ServiceError>;
async fn create_privilege(&self, privilege: &str) -> Result<(), ServiceError>;
async fn delete_privilege(&self, privilege: &str) -> Result<(), ServiceError>;
async fn get_all_privileges(&self) -> Result<Arc<[Privilege]>, ServiceError>;
async fn create_role(&self, role: &str, context: Self::Context) -> Result<(), ServiceError>;
async fn delete_role(&self, role: &str, context: Self::Context) -> Result<(), ServiceError>;
async fn get_all_roles(&self, context: Self::Context) -> Result<Arc<[Role]>, ServiceError>;
async fn add_user_role(&self, user: &str, role: &str) -> Result<(), ServiceError>;
async fn add_role_privilege(&self, role: &str, privilege: &str) -> Result<(), ServiceError>;
async fn delete_role_privilege(&self, role: &str, privilege: &str) -> Result<(), ServiceError>;
async fn delete_user_role(&self, user: &str, role: &str) -> Result<(), ServiceError>;
async fn create_privilege(
&self,
privilege: &str,
context: Self::Context,
) -> Result<(), ServiceError>;
async fn delete_privilege(
&self,
privilege: &str,
context: Self::Context,
) -> Result<(), ServiceError>;
async fn get_all_privileges(
&self,
context: Self::Context,
) -> Result<Arc<[Privilege]>, ServiceError>;
async fn add_user_role(
&self,
user: &str,
role: &str,
context: Self::Context,
) -> Result<(), ServiceError>;
async fn add_role_privilege(
&self,
role: &str,
privilege: &str,
context: Self::Context,
) -> Result<(), ServiceError>;
async fn delete_role_privilege(
&self,
role: &str,
privilege: &str,
context: Self::Context,
) -> Result<(), ServiceError>;
async fn delete_user_role(
&self,
user: &str,
role: &str,
context: Self::Context,
) -> Result<(), ServiceError>;
}

View file

@ -82,12 +82,14 @@ impl From<&Slot> for dao::slot::SlotEntity {
}
}
#[automock]
#[automock(type Context=();)]
#[async_trait]
pub trait SlotService {
async fn get_slots(&self) -> Result<Arc<[Slot]>, ServiceError>;
async fn get_slot(&self, id: &Uuid) -> Result<Slot, ServiceError>;
async fn create_slot(&self, slot: &Slot) -> Result<Slot, ServiceError>;
async fn delete_slot(&self, id: &Uuid) -> Result<(), ServiceError>;
async fn update_slot(&self, slot: &Slot) -> Result<(), ServiceError>;
type Context: Clone + Send + Sync + 'static;
async fn get_slots(&self, context: Self::Context) -> Result<Arc<[Slot]>, ServiceError>;
async fn get_slot(&self, id: &Uuid, context: Self::Context) -> Result<Slot, ServiceError>;
async fn create_slot(&self, slot: &Slot, context: Self::Context) -> Result<Slot, ServiceError>;
async fn delete_slot(&self, id: &Uuid, context: Self::Context) -> Result<(), ServiceError>;
async fn update_slot(&self, slot: &Slot, context: Self::Context) -> Result<(), ServiceError>;
}

View file

@ -0,0 +1,14 @@
use std::sync::Arc;
use async_trait::async_trait;
use mockall::automock;
use crate::ServiceError;
#[automock(type Context=();)]
#[async_trait]
pub trait UserService {
type Context: Clone + Send + Sync + 'static;
async fn current_user(&self, context: Self::Context) -> Result<Arc<str>, ServiceError>;
}