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

@@ -1,15 +1,25 @@
use std::collections::HashMap;
use chrono::Month;
use serde::{Deserialize, Serialize};
use crate::{
resident::Resident,
resident::{Resident, ResidentDTO},
schedule::{MonthlySchedule, ShiftType},
slot::{Day, ShiftPosition, Slot},
};
const YEAR: i32 = 2026;
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct UserConfigDTO {
month: usize,
year: i32,
holidays: Vec<usize>,
residents: Vec<ResidentDTO>,
toxic_pairs: Vec<(String, String)>,
}
#[derive(Debug)]
pub struct UserConfig {
month: Month,
@@ -36,6 +46,18 @@ impl UserConfig {
}
}
pub fn from_dto(dto: UserConfigDTO) -> Self {
Self {
month: Month::try_from(dto.month as u8).unwrap(),
year: dto.year,
holidays: dto.holidays,
residents: dto.residents.into_iter().map(Resident::from_dto).collect(),
toxic_pairs: dto.toxic_pairs,
workload_limits: HashMap::new(),
holiday_limits: HashMap::new(),
}
}
pub fn with_holidays(mut self, holidays: Vec<usize>) -> Self {
self.holidays = holidays;
self