Implement DTOs, add managed state for schedule, export to txt

This commit is contained in:
2026-01-11 22:28:10 +02:00
parent 53f8695572
commit 92a9c6d704
11 changed files with 254 additions and 70 deletions

View File

@@ -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,
}
}
}