Add endpoint to add extra_hours

This commit is contained in:
Simon Goller 2024-06-24 08:31:47 +02:00
parent d4adcb182f
commit c8f28e1f7b
11 changed files with 335 additions and 38 deletions

View file

@ -0,0 +1,111 @@
use std::sync::Arc;
use async_trait::async_trait;
use dao::extra_hours;
use service::{
extra_hours::ExtraHours,
permission::{Authentication, HR_PRIVILEGE},
ServiceError,
};
use uuid::Uuid;
pub struct ExtraHoursServiceImpl<
ExtraHoursDao: dao::extra_hours::ExtraHoursDao,
PermissionService: service::PermissionService,
ClockService: service::clock::ClockService,
UuidService: service::uuid_service::UuidService,
> {
extra_hours_dao: Arc<ExtraHoursDao>,
permission_service: Arc<PermissionService>,
clock_service: Arc<ClockService>,
uuid_service: Arc<UuidService>,
}
impl<ExtraHoursDao, PermissionService, ClockService, UuidService>
ExtraHoursServiceImpl<ExtraHoursDao, PermissionService, ClockService, UuidService>
where
ExtraHoursDao: dao::extra_hours::ExtraHoursDao + Sync + Send,
PermissionService: service::PermissionService + Sync + Send,
ClockService: service::clock::ClockService + Sync + Send,
UuidService: service::uuid_service::UuidService + Sync + Send,
{
pub fn new(
extra_hours_dao: Arc<ExtraHoursDao>,
permission_service: Arc<PermissionService>,
clock_service: Arc<ClockService>,
uuid_service: Arc<UuidService>,
) -> Self {
Self {
extra_hours_dao,
permission_service,
clock_service,
uuid_service,
}
}
}
#[async_trait]
impl<
ExtraHoursDao: dao::extra_hours::ExtraHoursDao + Sync + Send,
PermissionService: service::PermissionService + Sync + Send,
ClockService: service::clock::ClockService + Sync + Send,
UuidService: service::uuid_service::UuidService + Sync + Send,
> service::extra_hours::ExtraHoursService
for ExtraHoursServiceImpl<ExtraHoursDao, PermissionService, ClockService, UuidService>
{
type Context = PermissionService::Context;
async fn find_by_sales_person_id_and_year(
&self,
_sales_person_id: Uuid,
_year: u32,
_until_week: u8,
_context: Authentication<Self::Context>,
) -> Result<Arc<[ExtraHours]>, ServiceError> {
unimplemented!()
}
async fn create(
&self,
extra_hours: &ExtraHours,
context: Authentication<Self::Context>,
) -> Result<ExtraHours, ServiceError> {
self.permission_service
.check_permission(HR_PRIVILEGE, context)
.await?;
let mut extra_hours = extra_hours.to_owned();
if !extra_hours.id.is_nil() {
return Err(ServiceError::IdSetOnCreate);
}
if !extra_hours.version.is_nil() {
return Err(ServiceError::VersionSetOnCreate);
}
extra_hours.id = self.uuid_service.new_uuid("extra_hours_service::create id");
extra_hours.version = self
.uuid_service
.new_uuid("extra_hours_service::create version");
extra_hours.created = Some(self.clock_service.date_time_now());
let extra_hours_entity = extra_hours::ExtraHoursEntity::try_from(&extra_hours)?;
self.extra_hours_dao
.create(&extra_hours_entity, "extra_hours_service::create")
.await?;
Ok(extra_hours.into())
}
async fn update(
&self,
_entity: &ExtraHours,
_context: Authentication<Self::Context>,
) -> Result<ExtraHours, ServiceError> {
unimplemented!()
}
async fn delete(
&self,
_id: Uuid,
_context: Authentication<Self::Context>,
) -> Result<ExtraHours, ServiceError> {
unimplemented!()
}
}

View file

@ -4,6 +4,7 @@ use async_trait::async_trait;
pub mod booking;
pub mod clock;
pub mod extra_hours;
pub mod permission;
pub mod reporting;
pub mod sales_person;

View file

@ -124,7 +124,6 @@ pub fn find_working_hours_for_calendar_week(
year: u32,
week: u8,
) -> Option<&WorkingHoursEntity> {
dbg!((year, week));
working_hours.iter().find(|wh| {
(year, week) >= (wh.from_year, wh.from_calendar_week)
&& (year, week) <= (wh.to_year, wh.to_calendar_week)

View file

@ -87,14 +87,10 @@ where
.await
.is_err()
{
println!("No HR Role - remove sensitive data");
sales_persons.iter_mut().for_each(|sales_person| {
sales_person.is_paid = None;
});
} else {
println!("HR ROLE - no sensitive data removal");
}
Ok(sales_persons.into())
}
@ -128,7 +124,6 @@ where
.check_permission(HR_PRIVILEGE, context.clone())
);
shiftplanner.or(sales).or(hr)?;
println!("Has roles");
let mut sales_person = self
.sales_person_dao
.find_by_id(id)
@ -143,21 +138,17 @@ where
.await
.is_err()
{
println!("No HR Role - futher checks required");
if let (Some(current_user_id), Some(assigned_user)) = (
self.permission_service
.current_user_id(context.clone())
.await?,
self.get_assigned_user(id, Authentication::Full).await?,
) {
println!("Check if user ID matches");
current_user_id != assigned_user
} else {
println!("UserID or assigned user is missing - must remove sensitive data");
true
}
} else {
println!("HR Role - no sensitive data removal");
false
};