backend/model/dto/
plantings_impl.rs1use uuid::Uuid;
5
6use crate::model::{
7 dto::plantings::{
8 MovePlantingDto, PlantingDto, TransformPlantingDto, UpdateAddDatePlantingDto,
9 UpdatePlantingDto, UpdatePlantingNoteDto, UpdateRemoveDatePlantingDto,
10 },
11 entity::plantings::{NewPlanting, Planting, UpdatePlanting},
12};
13
14impl From<(Planting, Option<String>)> for PlantingDto {
15 fn from((planting, additional_name): (Planting, Option<String>)) -> Self {
16 Self {
17 additional_name,
18 ..planting.into()
19 }
20 }
21}
22
23impl From<Planting> for PlantingDto {
24 fn from(planting: Planting) -> Self {
25 Self {
26 id: planting.id,
27 plant_id: planting.plant_id,
28 layer_id: planting.layer_id,
29 created_at: Some(planting.created_at),
30 modified_at: Some(planting.modified_at),
31 created_by: Some(planting.created_by),
32 modified_by: Some(planting.modified_by),
33 x: planting.x,
34 y: planting.y,
35 size_x: planting.size_x,
36 size_y: planting.size_y,
37 height: planting.height,
38 rotation: planting.rotation,
39 add_date: planting.add_date,
40 remove_date: planting.remove_date,
41 seed_id: planting.seed_id,
42 is_area: planting.is_area,
43 additional_name: None,
44 notes: planting.notes,
45 }
46 }
47}
48
49impl From<(PlantingDto, Uuid)> for NewPlanting {
50 fn from((dto, user_id): (PlantingDto, Uuid)) -> Self {
51 Self {
52 id: dto.id,
53 plant_id: dto.plant_id,
54 layer_id: dto.layer_id,
55 created_by: user_id,
56 modified_by: user_id,
57 x: dto.x,
58 y: dto.y,
59 size_x: dto.size_x,
60 size_y: dto.size_y,
61 height: dto.height,
62 rotation: dto.rotation,
63 remove_date: Option::None,
64 add_date: dto.add_date,
65 seed_id: dto.seed_id,
66 is_area: dto.is_area,
67 }
68 }
69}
70
71impl From<TransformPlantingDto> for UpdatePlanting {
72 fn from(dto: TransformPlantingDto) -> Self {
73 Self {
74 id: dto.id,
75 x: Some(dto.x),
76 y: Some(dto.y),
77 rotation: Some(dto.rotation),
78 size_x: Some(dto.size_x),
79 size_y: Some(dto.size_y),
80 height: Some(dto.height),
81 ..Default::default()
82 }
83 }
84}
85
86impl From<MovePlantingDto> for UpdatePlanting {
87 fn from(dto: MovePlantingDto) -> Self {
88 Self {
89 id: dto.id,
90 x: Some(dto.x),
91 y: Some(dto.y),
92 ..Default::default()
93 }
94 }
95}
96
97impl From<UpdateAddDatePlantingDto> for UpdatePlanting {
98 fn from(dto: UpdateAddDatePlantingDto) -> Self {
99 Self {
100 id: dto.id,
101 add_date: Some(dto.add_date),
102 ..Default::default()
103 }
104 }
105}
106
107impl From<UpdateRemoveDatePlantingDto> for UpdatePlanting {
108 fn from(dto: UpdateRemoveDatePlantingDto) -> Self {
109 Self {
110 id: dto.id,
111 remove_date: Some(dto.remove_date),
112 ..Default::default()
113 }
114 }
115}
116
117impl From<UpdatePlantingNoteDto> for UpdatePlanting {
118 fn from(dto: UpdatePlantingNoteDto) -> Self {
119 Self {
120 id: dto.id,
121 notes: Some(dto.notes),
122 ..Default::default()
123 }
124 }
125}
126
127impl From<UpdatePlantingDto> for Vec<UpdatePlanting> {
128 fn from(dto: UpdatePlantingDto) -> Self {
129 match dto {
130 UpdatePlantingDto::Transform(vec) => vec.into_iter().map(Into::into).collect(),
131 UpdatePlantingDto::Move(vec) => vec.into_iter().map(Into::into).collect(),
132 UpdatePlantingDto::UpdateAddDate(vec) => vec.into_iter().map(Into::into).collect(),
133 UpdatePlantingDto::UpdateRemoveDate(vec) => vec.into_iter().map(Into::into).collect(),
134 UpdatePlantingDto::UpdateNote(vec) => vec.into_iter().map(Into::into).collect(),
135 }
136 }
137}