Wrap Context with Autentication enum
Context should contain information which is required to get the information if the service call is authenticated. Context could be the username for example. But services call other services internally and for this, authentication must not be checked. In this case, they can now pass Authentication::Full which always successfully authenticates.
This commit is contained in:
parent
bf94ec33de
commit
b0000c0117
18 changed files with 252 additions and 217 deletions
|
|
@ -1,10 +1,12 @@
|
|||
use std::sync::Arc;
|
||||
use std::fmt::Debug;
|
||||
|
||||
use async_trait::async_trait;
|
||||
use mockall::automock;
|
||||
use uuid::Uuid;
|
||||
|
||||
use crate::ServiceError;
|
||||
use crate::permission::Authentication;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub struct SalesPerson {
|
||||
|
|
@ -40,31 +42,31 @@ impl From<&SalesPerson> for dao::sales_person::SalesPersonEntity {
|
|||
#[automock(type Context=();)]
|
||||
#[async_trait]
|
||||
pub trait SalesPersonService {
|
||||
type Context: Clone + Send + Sync + 'static;
|
||||
type Context: Clone + Debug + PartialEq + Eq + Send + Sync + 'static;
|
||||
|
||||
async fn get_all(&self, context: Self::Context) -> Result<Arc<[SalesPerson]>, ServiceError>;
|
||||
async fn get(&self, id: Uuid, context: Self::Context) -> Result<SalesPerson, ServiceError>;
|
||||
async fn exists(&self, id: Uuid, context: Self::Context) -> Result<bool, ServiceError>;
|
||||
async fn get_all(&self, context: Authentication<Self::Context>) -> Result<Arc<[SalesPerson]>, ServiceError>;
|
||||
async fn get(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<SalesPerson, ServiceError>;
|
||||
async fn exists(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<bool, ServiceError>;
|
||||
async fn create(
|
||||
&self,
|
||||
item: &SalesPerson,
|
||||
context: Self::Context,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<SalesPerson, ServiceError>;
|
||||
async fn update(
|
||||
&self,
|
||||
item: &SalesPerson,
|
||||
context: Self::Context,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<SalesPerson, ServiceError>;
|
||||
async fn delete(&self, id: Uuid, context: Self::Context) -> Result<(), ServiceError>;
|
||||
async fn delete(&self, id: Uuid, context: Authentication<Self::Context>) -> Result<(), ServiceError>;
|
||||
async fn get_assigned_user(
|
||||
&self,
|
||||
sales_person_id: Uuid,
|
||||
context: Self::Context,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<Option<Arc<str>>, ServiceError>;
|
||||
async fn set_user(
|
||||
&self,
|
||||
sales_person_id: Uuid,
|
||||
user_id: Option<Arc<str>>,
|
||||
context: Self::Context,
|
||||
context: Authentication<Self::Context>,
|
||||
) -> Result<(), ServiceError>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue