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