Add REST endpoint for slot
This commit is contained in:
parent
82e89baeeb
commit
8f378472ea
28 changed files with 1925 additions and 28 deletions
|
|
@ -10,3 +10,7 @@ async-trait = "0.1.80"
|
|||
mockall = "0.12.1"
|
||||
thiserror = "1.0.59"
|
||||
uuid = "1.8"
|
||||
|
||||
[dependencies.time]
|
||||
version = "0.3.36"
|
||||
features = ["parsing"]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ use async_trait::async_trait;
|
|||
use mockall::automock;
|
||||
use thiserror::Error;
|
||||
|
||||
mod permission;
|
||||
pub mod permission;
|
||||
pub mod slot;
|
||||
|
||||
pub use permission::MockPermissionDao;
|
||||
pub use permission::PermissionDao;
|
||||
|
|
@ -15,7 +16,16 @@ pub use permission::UserEntity;
|
|||
#[derive(Error, Debug)]
|
||||
pub enum DaoError {
|
||||
#[error("Database query error: {0}")]
|
||||
DatabaseQueryError(#[from] Box<dyn std::error::Error>),
|
||||
DatabaseQueryError(#[from] Box<dyn std::error::Error + Send + Sync>),
|
||||
|
||||
#[error("Uuid error: {0}")]
|
||||
UuidError(#[from] uuid::Error),
|
||||
|
||||
#[error("Invalid day of week number: {0}")]
|
||||
InvalidDayOfWeek(u8),
|
||||
|
||||
#[error("Date/Time parse error: {0}")]
|
||||
DateTimeParseError(#[from] time::error::Parse),
|
||||
}
|
||||
|
||||
#[automock]
|
||||
|
|
|
|||
65
dao/src/slot.rs
Normal file
65
dao/src/slot.rs
Normal 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>;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue