Implement DTOs, add managed state for schedule, export to txt
This commit is contained in:
@@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
schedule::ShiftType,
|
||||
slot::{Day, Slot},
|
||||
slot::{Day, ShiftPosition, Slot},
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
@@ -17,6 +17,18 @@ pub struct Resident {
|
||||
pub reduced_load: bool,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, Clone)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ResidentDTO {
|
||||
id: String,
|
||||
name: String,
|
||||
negative_shifts: Vec<usize>,
|
||||
manual_shifts: Vec<Slot>,
|
||||
max_shifts: Option<usize>,
|
||||
allowed_types: Vec<ShiftType>,
|
||||
reduced_load: bool,
|
||||
}
|
||||
|
||||
impl Resident {
|
||||
pub fn new(id: &str, name: &str) -> Self {
|
||||
Self {
|
||||
@@ -43,4 +55,30 @@ impl Resident {
|
||||
self.reduced_load = true;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn from_dto(dto: ResidentDTO) -> Self {
|
||||
Self {
|
||||
id: dto.id,
|
||||
name: dto.name,
|
||||
negative_shifts: dto
|
||||
.negative_shifts
|
||||
.into_iter()
|
||||
.map(|d| Day(d as u8))
|
||||
.collect(),
|
||||
manual_shifts: dto
|
||||
.manual_shifts
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
Slot {
|
||||
day: s.day,
|
||||
// FIXME: frontend always brings resident manual shifts as first
|
||||
position: ShiftPosition::First,
|
||||
}
|
||||
})
|
||||
.collect(),
|
||||
max_shifts: dto.max_shifts,
|
||||
allowed_types: dto.allowed_types,
|
||||
reduced_load: dto.reduced_load,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user