Add REST endpoint for slot

This commit is contained in:
Simon Goller 2024-05-02 23:25:04 +02:00
parent 82e89baeeb
commit 8f378472ea
28 changed files with 1925 additions and 28 deletions

65
dao/src/slot.rs Normal file
View file

@ -0,0 +1,65 @@
use std::sync::Arc;
use async_trait::async_trait;
use mockall::automock;
use uuid::Uuid;
use crate::DaoError;
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub enum DayOfWeek {
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday,
Sunday,
}
impl DayOfWeek {
pub fn from_number(number: u8) -> Option<Self> {
match number {
1 => Some(DayOfWeek::Monday),
2 => Some(DayOfWeek::Tuesday),
3 => Some(DayOfWeek::Wednesday),
4 => Some(DayOfWeek::Thursday),
5 => Some(DayOfWeek::Friday),
6 => Some(DayOfWeek::Saturday),
7 => Some(DayOfWeek::Sunday),
_ => None,
}
}
pub fn to_number(&self) -> u8 {
match self {
DayOfWeek::Monday => 1,
DayOfWeek::Tuesday => 2,
DayOfWeek::Wednesday => 3,
DayOfWeek::Thursday => 4,
DayOfWeek::Friday => 5,
DayOfWeek::Saturday => 6,
DayOfWeek::Sunday => 7,
}
}
}
#[derive(Debug, PartialEq, Eq)]
pub struct SlotEntity {
pub id: Uuid,
pub day_of_week: DayOfWeek,
pub from: time::Time,
pub to: time::Time,
pub valid_from: time::Date,
pub valid_to: Option<time::Date>,
pub deleted: Option<time::PrimitiveDateTime>,
pub version: Uuid,
}
#[automock]
#[async_trait]
pub trait SlotDao {
async fn get_slots(&self) -> Result<Arc<[SlotEntity]>, DaoError>;
async fn get_slot(&self, id: &Uuid) -> Result<Option<SlotEntity>, DaoError>;
async fn create_slot(&self, slot: &SlotEntity, process: &str) -> Result<(), DaoError>;
//async fn delete_slot(&self, id: &Uuid, process: &str) -> Result<(), DaoError>;
async fn update_slot(&self, slot: &SlotEntity, process: &str) -> Result<(), DaoError>;
}