1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//! Contains the implementation of [`PlantsSummaryDto`].

use crate::model::{entity::Plants, r#enum::life_cycle::LifeCycle};

use super::PlantsSummaryDto;

impl From<Plants> for PlantsSummaryDto {
    fn from(plants: Plants) -> Self {
        let life_cycle: Vec<LifeCycle> = plants
            .life_cycle
            .map_or(vec![], |v| v.into_iter().flatten().collect());

        Self {
            id: plants.id,
            unique_name: plants.unique_name,
            common_name_en: plants.common_name_en,
            common_name_de: plants.common_name_de,
            spread: plants.spread,
            life_cycle,
        }
    }
}

impl<T> From<(T, Plants)> for PlantsSummaryDto {
    fn from((_, plants): (T, Plants)) -> Self {
        Self::from(plants)
    }
}