use std::fmt::Debug; use std::sync::Arc; use async_trait::async_trait; use mockall::automock; use uuid::Uuid; use crate::permission::Authentication; use crate::ServiceError; #[derive(Clone, Debug, PartialEq, Eq)] pub struct SalesPerson { pub id: Uuid, pub name: Arc, pub inactive: bool, pub deleted: Option, pub version: Uuid, } impl From<&dao::sales_person::SalesPersonEntity> for SalesPerson { fn from(sales_person: &dao::sales_person::SalesPersonEntity) -> Self { Self { id: sales_person.id, name: sales_person.name.clone(), inactive: sales_person.inactive, deleted: sales_person.deleted, version: sales_person.version, } } } impl From<&SalesPerson> for dao::sales_person::SalesPersonEntity { fn from(sales_person: &SalesPerson) -> Self { Self { id: sales_person.id, name: sales_person.name.clone(), inactive: sales_person.inactive, deleted: sales_person.deleted, version: sales_person.version, } } } #[automock(type Context=();)] #[async_trait] pub trait SalesPersonService { type Context: Clone + Debug + PartialEq + Eq + Send + Sync + 'static; async fn get_all( &self, context: Authentication, ) -> Result, ServiceError>; async fn get( &self, id: Uuid, context: Authentication, ) -> Result; async fn exists( &self, id: Uuid, context: Authentication, ) -> Result; async fn create( &self, item: &SalesPerson, context: Authentication, ) -> Result; async fn update( &self, item: &SalesPerson, context: Authentication, ) -> Result; async fn delete( &self, id: Uuid, context: Authentication, ) -> Result<(), ServiceError>; async fn get_assigned_user( &self, sales_person_id: Uuid, context: Authentication, ) -> Result>, ServiceError>; async fn set_user( &self, sales_person_id: Uuid, user_id: Option>, context: Authentication, ) -> Result<(), ServiceError>; }