backend/model/dto/
seed_impl.rs

1//! Contains the implementation of [`SeedDto`].
2
3use crate::model::entity::Seed;
4
5use super::SeedDto;
6
7impl From<Seed> for SeedDto {
8    fn from(seed: Seed) -> Self {
9        Self {
10            id: seed.id,
11            name: seed.name,
12            plant_id: seed.plant_id,
13            harvest_year: seed.harvest_year,
14            quantity: seed.quantity,
15            use_by: seed.use_by,
16            origin: seed.origin,
17            taste: seed.taste,
18            yield_: seed.yield_,
19            generation: seed.generation,
20            quality: seed.quality,
21            price: seed.price,
22            notes: seed.notes,
23            created_by: seed.created_by,
24            archived_at: seed.archived_at.map(|date| format!("{date}")),
25        }
26    }
27}
28
29impl From<(f32, Seed)> for SeedDto {
30    fn from((_, seed): (f32, Seed)) -> Self {
31        Self {
32            id: seed.id,
33            name: seed.name,
34            plant_id: seed.plant_id,
35            harvest_year: seed.harvest_year,
36            quantity: seed.quantity,
37            use_by: seed.use_by,
38            origin: seed.origin,
39            taste: seed.taste,
40            yield_: seed.yield_,
41            generation: seed.generation,
42            quality: seed.quality,
43            price: seed.price,
44            notes: seed.notes,
45            created_by: seed.created_by,
46            archived_at: seed.archived_at.map(|date| format!("{date}")),
47        }
48    }
49}