Replace from_dto fn with From trait impl
This commit is contained in:
@@ -50,20 +50,6 @@ 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(),
|
||||
shift_type_limits: HashMap::new(),
|
||||
shift_type_threshold: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_holidays(mut self, holidays: Vec<usize>) -> Self {
|
||||
self.holidays = holidays;
|
||||
self
|
||||
@@ -184,7 +170,7 @@ impl UserConfig {
|
||||
}
|
||||
}
|
||||
|
||||
/// shift type count fairness
|
||||
/// shift type count fairness
|
||||
pub fn calculate_shift_type_fairness(&mut self) {
|
||||
let mut global_supply = self.get_initial_supply();
|
||||
let mut local_limits = HashMap::new();
|
||||
@@ -323,6 +309,22 @@ impl UserConfig {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<UserConfigDTO> for UserConfig {
|
||||
fn from(value: UserConfigDTO) -> Self {
|
||||
Self {
|
||||
month: Month::try_from(value.month as u8).unwrap(),
|
||||
year: value.year,
|
||||
holidays: value.holidays,
|
||||
residents: value.residents.into_iter().map(Resident::from).collect(),
|
||||
toxic_pairs: value.toxic_pairs,
|
||||
workload_limits: HashMap::new(),
|
||||
holiday_limits: HashMap::new(),
|
||||
shift_type_limits: HashMap::new(),
|
||||
shift_type_threshold: HashMap::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
Reference in New Issue
Block a user