1use common::entities::Frame;
4pub use common::entities::FramePosition;
5use common::types::EntityId;
6use serde::{Deserialize, Serialize};
7use std::convert::From;
8
9#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
10pub struct FrameDto {
11 pub id: EntityId,
12 pub created_at: chrono::DateTime<chrono::Utc>,
13 pub updated_at: chrono::DateTime<chrono::Utc>,
14 pub parent_frame: Option<EntityId>,
15 pub blocks: Vec<EntityId>,
16 pub child_order: Vec<i64>,
17 pub fmt_height: Option<i64>,
18 pub fmt_width: Option<i64>,
19 pub fmt_top_margin: Option<i64>,
20 pub fmt_bottom_margin: Option<i64>,
21 pub fmt_left_margin: Option<i64>,
22 pub fmt_right_margin: Option<i64>,
23 pub fmt_padding: Option<i64>,
24 pub fmt_border: Option<i64>,
25 pub fmt_position: Option<FramePosition>,
26 pub table: Option<EntityId>,
27}
28
29impl From<FrameDto> for Frame {
30 fn from(dto: FrameDto) -> Self {
31 Frame {
32 id: dto.id,
33 created_at: dto.created_at,
34 updated_at: dto.updated_at,
35 parent_frame: dto.parent_frame,
36 blocks: dto.blocks,
37 child_order: dto.child_order,
38 fmt_height: dto.fmt_height,
39 fmt_width: dto.fmt_width,
40 fmt_top_margin: dto.fmt_top_margin,
41 fmt_bottom_margin: dto.fmt_bottom_margin,
42 fmt_left_margin: dto.fmt_left_margin,
43 fmt_right_margin: dto.fmt_right_margin,
44 fmt_padding: dto.fmt_padding,
45 fmt_border: dto.fmt_border,
46 fmt_position: dto.fmt_position,
47 table: dto.table,
48 }
49 }
50}
51
52impl From<&FrameDto> for Frame {
53 fn from(dto: &FrameDto) -> Self {
54 Frame {
55 id: dto.id,
56 created_at: dto.created_at,
57 updated_at: dto.updated_at,
58 parent_frame: dto.parent_frame,
59 blocks: dto.blocks.clone(),
60 child_order: dto.child_order.clone(),
61 fmt_height: dto.fmt_height,
62 fmt_width: dto.fmt_width,
63 fmt_top_margin: dto.fmt_top_margin,
64 fmt_bottom_margin: dto.fmt_bottom_margin,
65 fmt_left_margin: dto.fmt_left_margin,
66 fmt_right_margin: dto.fmt_right_margin,
67 fmt_padding: dto.fmt_padding,
68 fmt_border: dto.fmt_border,
69 fmt_position: dto.fmt_position.clone(),
70 table: dto.table,
71 }
72 }
73}
74
75impl From<Frame> for FrameDto {
76 fn from(entity: Frame) -> Self {
77 FrameDto {
78 id: entity.id,
79 created_at: entity.created_at,
80 updated_at: entity.updated_at,
81 parent_frame: entity.parent_frame,
82 blocks: entity.blocks,
83 child_order: entity.child_order,
84 fmt_height: entity.fmt_height,
85 fmt_width: entity.fmt_width,
86 fmt_top_margin: entity.fmt_top_margin,
87 fmt_bottom_margin: entity.fmt_bottom_margin,
88 fmt_left_margin: entity.fmt_left_margin,
89 fmt_right_margin: entity.fmt_right_margin,
90 fmt_padding: entity.fmt_padding,
91 fmt_border: entity.fmt_border,
92 fmt_position: entity.fmt_position,
93 table: entity.table,
94 }
95 }
96}
97
98#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
99pub struct CreateFrameDto {
100 pub created_at: chrono::DateTime<chrono::Utc>,
101 pub updated_at: chrono::DateTime<chrono::Utc>,
102 pub parent_frame: Option<EntityId>,
103 pub blocks: Vec<EntityId>,
104 pub child_order: Vec<i64>,
105 pub fmt_height: Option<i64>,
106 pub fmt_width: Option<i64>,
107 pub fmt_top_margin: Option<i64>,
108 pub fmt_bottom_margin: Option<i64>,
109 pub fmt_left_margin: Option<i64>,
110 pub fmt_right_margin: Option<i64>,
111 pub fmt_padding: Option<i64>,
112 pub fmt_border: Option<i64>,
113 pub fmt_position: Option<FramePosition>,
114 pub table: Option<EntityId>,
115}
116
117impl From<CreateFrameDto> for Frame {
118 fn from(dto: CreateFrameDto) -> Self {
119 Frame {
120 id: 0,
121 created_at: dto.created_at,
122 updated_at: dto.updated_at,
123 parent_frame: dto.parent_frame,
124 blocks: dto.blocks,
125 child_order: dto.child_order,
126 fmt_height: dto.fmt_height,
127 fmt_width: dto.fmt_width,
128 fmt_top_margin: dto.fmt_top_margin,
129 fmt_bottom_margin: dto.fmt_bottom_margin,
130 fmt_left_margin: dto.fmt_left_margin,
131 fmt_right_margin: dto.fmt_right_margin,
132 fmt_padding: dto.fmt_padding,
133 fmt_border: dto.fmt_border,
134 fmt_position: dto.fmt_position,
135 table: dto.table,
136 }
137 }
138}
139
140impl From<&CreateFrameDto> for Frame {
141 fn from(dto: &CreateFrameDto) -> Self {
142 Frame {
143 id: 0,
144 created_at: dto.created_at,
145 updated_at: dto.updated_at,
146 parent_frame: dto.parent_frame,
147 blocks: dto.blocks.clone(),
148 child_order: dto.child_order.clone(),
149 fmt_height: dto.fmt_height,
150 fmt_width: dto.fmt_width,
151 fmt_top_margin: dto.fmt_top_margin,
152 fmt_bottom_margin: dto.fmt_bottom_margin,
153 fmt_left_margin: dto.fmt_left_margin,
154 fmt_right_margin: dto.fmt_right_margin,
155 fmt_padding: dto.fmt_padding,
156 fmt_border: dto.fmt_border,
157 fmt_position: dto.fmt_position.clone(),
158 table: dto.table,
159 }
160 }
161}
162
163impl From<Frame> for CreateFrameDto {
164 fn from(entity: Frame) -> Self {
165 CreateFrameDto {
166 created_at: entity.created_at,
167 updated_at: entity.updated_at,
168 parent_frame: entity.parent_frame,
169 blocks: entity.blocks,
170 child_order: entity.child_order,
171 fmt_height: entity.fmt_height,
172 fmt_width: entity.fmt_width,
173 fmt_top_margin: entity.fmt_top_margin,
174 fmt_bottom_margin: entity.fmt_bottom_margin,
175 fmt_left_margin: entity.fmt_left_margin,
176 fmt_right_margin: entity.fmt_right_margin,
177 fmt_padding: entity.fmt_padding,
178 fmt_border: entity.fmt_border,
179 fmt_position: entity.fmt_position,
180 table: entity.table,
181 }
182 }
183}
184
185#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
186pub struct UpdateFrameDto {
187 pub id: EntityId,
188 pub created_at: chrono::DateTime<chrono::Utc>,
189 pub updated_at: chrono::DateTime<chrono::Utc>,
190 pub child_order: Vec<i64>,
191 pub fmt_height: Option<i64>,
192 pub fmt_width: Option<i64>,
193 pub fmt_top_margin: Option<i64>,
194 pub fmt_bottom_margin: Option<i64>,
195 pub fmt_left_margin: Option<i64>,
196 pub fmt_right_margin: Option<i64>,
197 pub fmt_padding: Option<i64>,
198 pub fmt_border: Option<i64>,
199 pub fmt_position: Option<FramePosition>,
200}
201
202impl From<UpdateFrameDto> for Frame {
203 fn from(dto: UpdateFrameDto) -> Self {
204 Frame {
205 id: dto.id,
206 created_at: dto.created_at,
207 updated_at: dto.updated_at,
208 child_order: dto.child_order,
209 fmt_height: dto.fmt_height,
210 fmt_width: dto.fmt_width,
211 fmt_top_margin: dto.fmt_top_margin,
212 fmt_bottom_margin: dto.fmt_bottom_margin,
213 fmt_left_margin: dto.fmt_left_margin,
214 fmt_right_margin: dto.fmt_right_margin,
215 fmt_padding: dto.fmt_padding,
216 fmt_border: dto.fmt_border,
217 fmt_position: dto.fmt_position,
218 parent_frame: Default::default(),
219 blocks: Default::default(),
220 table: Default::default(),
221 }
222 }
223}
224
225impl From<&UpdateFrameDto> for Frame {
226 fn from(dto: &UpdateFrameDto) -> Self {
227 Frame {
228 id: dto.id,
229 created_at: dto.created_at,
230 updated_at: dto.updated_at,
231 child_order: dto.child_order.clone(),
232 fmt_height: dto.fmt_height,
233 fmt_width: dto.fmt_width,
234 fmt_top_margin: dto.fmt_top_margin,
235 fmt_bottom_margin: dto.fmt_bottom_margin,
236 fmt_left_margin: dto.fmt_left_margin,
237 fmt_right_margin: dto.fmt_right_margin,
238 fmt_padding: dto.fmt_padding,
239 fmt_border: dto.fmt_border,
240 fmt_position: dto.fmt_position.clone(),
241 parent_frame: Default::default(),
242 blocks: Default::default(),
243 table: Default::default(),
244 }
245 }
246}
247
248impl From<Frame> for UpdateFrameDto {
249 fn from(entity: Frame) -> Self {
250 UpdateFrameDto {
251 id: entity.id,
252 created_at: entity.created_at,
253 updated_at: entity.updated_at,
254 child_order: entity.child_order,
255 fmt_height: entity.fmt_height,
256 fmt_width: entity.fmt_width,
257 fmt_top_margin: entity.fmt_top_margin,
258 fmt_bottom_margin: entity.fmt_bottom_margin,
259 fmt_left_margin: entity.fmt_left_margin,
260 fmt_right_margin: entity.fmt_right_margin,
261 fmt_padding: entity.fmt_padding,
262 fmt_border: entity.fmt_border,
263 fmt_position: entity.fmt_position,
264 }
265 }
266}
267
268impl From<FrameDto> for UpdateFrameDto {
269 fn from(dto: FrameDto) -> Self {
270 UpdateFrameDto {
271 id: dto.id,
272 created_at: dto.created_at,
273 updated_at: dto.updated_at,
274 child_order: dto.child_order,
275 fmt_height: dto.fmt_height,
276 fmt_width: dto.fmt_width,
277 fmt_top_margin: dto.fmt_top_margin,
278 fmt_bottom_margin: dto.fmt_bottom_margin,
279 fmt_left_margin: dto.fmt_left_margin,
280 fmt_right_margin: dto.fmt_right_margin,
281 fmt_padding: dto.fmt_padding,
282 fmt_border: dto.fmt_border,
283 fmt_position: dto.fmt_position,
284 }
285 }
286}
287pub use common::direct_access::frame::FrameRelationshipField;
288
289#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
290pub struct FrameRelationshipDto {
291 pub id: EntityId,
292 pub field: FrameRelationshipField,
293 pub right_ids: Vec<EntityId>,
294}