Files
rota/src-tauri/src/resident.rs

85 lines
2.2 KiB
Rust

use serde::{Deserialize, Serialize};
use crate::{
schedule::ShiftType,
slot::{Day, ShiftPosition, Slot},
};
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Resident {
pub id: String,
pub name: String,
pub negative_shifts: Vec<Day>,
pub manual_shifts: Vec<Slot>,
pub max_shifts: Option<usize>,
pub allowed_types: Vec<ShiftType>,
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 {
id: id.to_string(),
name: name.to_string(),
negative_shifts: Vec::new(),
manual_shifts: Vec::new(),
max_shifts: None,
allowed_types: vec![
ShiftType::OpenFirst,
ShiftType::OpenSecond,
ShiftType::Closed,
],
reduced_load: false,
}
}
pub fn with_max_shifts(mut self, max_shifts: usize) -> Self {
self.max_shifts = Some(max_shifts);
self
}
pub fn with_reduced_load(mut self) -> Self {
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,
}
}
}