Implement DTOs, add managed state for schedule, export to txt
This commit is contained in:
@@ -4,12 +4,33 @@ use std::collections::HashMap;
|
||||
use crate::{
|
||||
config::UserConfig,
|
||||
resident::Resident,
|
||||
slot::{Day, Slot},
|
||||
slot::{Day, ShiftPosition, Slot},
|
||||
};
|
||||
|
||||
use serde::Serializer;
|
||||
|
||||
impl Serialize for MonthlySchedule {
|
||||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
|
||||
where
|
||||
S: Serializer,
|
||||
{
|
||||
use serde::ser::SerializeMap;
|
||||
let mut map = serializer.serialize_map(Some(self.0.len()))?;
|
||||
for (slot, name) in &self.0 {
|
||||
let pos_str = match slot.position {
|
||||
ShiftPosition::First => "First",
|
||||
ShiftPosition::Second => "Second",
|
||||
};
|
||||
let key = format!("{}-{}", slot.day.0, pos_str);
|
||||
map.serialize_entry(&key, name)?;
|
||||
}
|
||||
map.end()
|
||||
}
|
||||
}
|
||||
|
||||
// each slot has one resident
|
||||
// a day can span between 1 or 2 slots depending on if it is open(odd) or closed(even)
|
||||
#[derive(Debug)]
|
||||
#[derive(Deserialize, Debug, Clone)]
|
||||
pub struct MonthlySchedule(HashMap<Slot, String>);
|
||||
|
||||
impl MonthlySchedule {
|
||||
@@ -179,7 +200,7 @@ impl MonthlySchedule {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
|
||||
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
|
||||
pub enum ShiftType {
|
||||
Closed,
|
||||
OpenFirst,
|
||||
|
||||
Reference in New Issue
Block a user