1pub use common::entities::Alignment;
4use common::entities::Block;
5pub use common::entities::MarkerType;
6pub use common::entities::TextDirection;
7use common::types::EntityId;
8use serde::{Deserialize, Serialize};
9use std::convert::From;
10
11#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
12pub struct BlockDto {
13 pub id: EntityId,
14 pub created_at: chrono::DateTime<chrono::Utc>,
15 pub updated_at: chrono::DateTime<chrono::Utc>,
16 pub elements: Vec<EntityId>,
17 pub list: Option<EntityId>,
18 pub text_length: i64,
19 pub document_position: i64,
20 pub plain_text: String,
21 pub fmt_alignment: Option<Alignment>,
22 pub fmt_top_margin: Option<i64>,
23 pub fmt_bottom_margin: Option<i64>,
24 pub fmt_left_margin: Option<i64>,
25 pub fmt_right_margin: Option<i64>,
26 pub fmt_heading_level: Option<i64>,
27 pub fmt_indent: Option<i64>,
28 pub fmt_text_indent: Option<i64>,
29 pub fmt_marker: Option<MarkerType>,
30 pub fmt_tab_positions: Vec<i64>,
31 pub fmt_line_height: Option<i64>,
32 pub fmt_non_breakable_lines: Option<bool>,
33 pub fmt_direction: Option<TextDirection>,
34 pub fmt_background_color: Option<String>,
35 pub fmt_is_code_block: Option<bool>,
36 pub fmt_code_language: Option<String>,
37}
38
39impl From<BlockDto> for Block {
40 fn from(dto: BlockDto) -> Self {
41 Block {
42 id: dto.id,
43 created_at: dto.created_at,
44 updated_at: dto.updated_at,
45 elements: dto.elements,
46 list: dto.list,
47 text_length: dto.text_length,
48 document_position: dto.document_position,
49 plain_text: dto.plain_text,
50 fmt_alignment: dto.fmt_alignment,
51 fmt_top_margin: dto.fmt_top_margin,
52 fmt_bottom_margin: dto.fmt_bottom_margin,
53 fmt_left_margin: dto.fmt_left_margin,
54 fmt_right_margin: dto.fmt_right_margin,
55 fmt_heading_level: dto.fmt_heading_level,
56 fmt_indent: dto.fmt_indent,
57 fmt_text_indent: dto.fmt_text_indent,
58 fmt_marker: dto.fmt_marker,
59 fmt_tab_positions: dto.fmt_tab_positions,
60 fmt_line_height: dto.fmt_line_height,
61 fmt_non_breakable_lines: dto.fmt_non_breakable_lines,
62 fmt_direction: dto.fmt_direction,
63 fmt_background_color: dto.fmt_background_color,
64 fmt_is_code_block: dto.fmt_is_code_block,
65 fmt_code_language: dto.fmt_code_language,
66 }
67 }
68}
69
70impl From<&BlockDto> for Block {
71 fn from(dto: &BlockDto) -> Self {
72 Block {
73 id: dto.id,
74 created_at: dto.created_at,
75 updated_at: dto.updated_at,
76 elements: dto.elements.clone(),
77 list: dto.list,
78 text_length: dto.text_length,
79 document_position: dto.document_position,
80 plain_text: dto.plain_text.clone(),
81 fmt_alignment: dto.fmt_alignment.clone(),
82 fmt_top_margin: dto.fmt_top_margin,
83 fmt_bottom_margin: dto.fmt_bottom_margin,
84 fmt_left_margin: dto.fmt_left_margin,
85 fmt_right_margin: dto.fmt_right_margin,
86 fmt_heading_level: dto.fmt_heading_level,
87 fmt_indent: dto.fmt_indent,
88 fmt_text_indent: dto.fmt_text_indent,
89 fmt_marker: dto.fmt_marker.clone(),
90 fmt_tab_positions: dto.fmt_tab_positions.clone(),
91 fmt_line_height: dto.fmt_line_height,
92 fmt_non_breakable_lines: dto.fmt_non_breakable_lines,
93 fmt_direction: dto.fmt_direction.clone(),
94 fmt_background_color: dto.fmt_background_color.clone(),
95 fmt_is_code_block: dto.fmt_is_code_block,
96 fmt_code_language: dto.fmt_code_language.clone(),
97 }
98 }
99}
100
101impl From<Block> for BlockDto {
102 fn from(entity: Block) -> Self {
103 BlockDto {
104 id: entity.id,
105 created_at: entity.created_at,
106 updated_at: entity.updated_at,
107 elements: entity.elements,
108 list: entity.list,
109 text_length: entity.text_length,
110 document_position: entity.document_position,
111 plain_text: entity.plain_text,
112 fmt_alignment: entity.fmt_alignment,
113 fmt_top_margin: entity.fmt_top_margin,
114 fmt_bottom_margin: entity.fmt_bottom_margin,
115 fmt_left_margin: entity.fmt_left_margin,
116 fmt_right_margin: entity.fmt_right_margin,
117 fmt_heading_level: entity.fmt_heading_level,
118 fmt_indent: entity.fmt_indent,
119 fmt_text_indent: entity.fmt_text_indent,
120 fmt_marker: entity.fmt_marker,
121 fmt_tab_positions: entity.fmt_tab_positions,
122 fmt_line_height: entity.fmt_line_height,
123 fmt_non_breakable_lines: entity.fmt_non_breakable_lines,
124 fmt_direction: entity.fmt_direction,
125 fmt_background_color: entity.fmt_background_color,
126 fmt_is_code_block: entity.fmt_is_code_block,
127 fmt_code_language: entity.fmt_code_language,
128 }
129 }
130}
131
132#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
133pub struct CreateBlockDto {
134 pub created_at: chrono::DateTime<chrono::Utc>,
135 pub updated_at: chrono::DateTime<chrono::Utc>,
136 pub elements: Vec<EntityId>,
137 pub list: Option<EntityId>,
138 pub text_length: i64,
139 pub document_position: i64,
140 pub plain_text: String,
141 pub fmt_alignment: Option<Alignment>,
142 pub fmt_top_margin: Option<i64>,
143 pub fmt_bottom_margin: Option<i64>,
144 pub fmt_left_margin: Option<i64>,
145 pub fmt_right_margin: Option<i64>,
146 pub fmt_heading_level: Option<i64>,
147 pub fmt_indent: Option<i64>,
148 pub fmt_text_indent: Option<i64>,
149 pub fmt_marker: Option<MarkerType>,
150 pub fmt_tab_positions: Vec<i64>,
151 pub fmt_line_height: Option<i64>,
152 pub fmt_non_breakable_lines: Option<bool>,
153 pub fmt_direction: Option<TextDirection>,
154 pub fmt_background_color: Option<String>,
155 pub fmt_is_code_block: Option<bool>,
156 pub fmt_code_language: Option<String>,
157}
158
159impl From<CreateBlockDto> for Block {
160 fn from(dto: CreateBlockDto) -> Self {
161 Block {
162 id: 0,
163 created_at: dto.created_at,
164 updated_at: dto.updated_at,
165 elements: dto.elements,
166 list: dto.list,
167 text_length: dto.text_length,
168 document_position: dto.document_position,
169 plain_text: dto.plain_text,
170 fmt_alignment: dto.fmt_alignment,
171 fmt_top_margin: dto.fmt_top_margin,
172 fmt_bottom_margin: dto.fmt_bottom_margin,
173 fmt_left_margin: dto.fmt_left_margin,
174 fmt_right_margin: dto.fmt_right_margin,
175 fmt_heading_level: dto.fmt_heading_level,
176 fmt_indent: dto.fmt_indent,
177 fmt_text_indent: dto.fmt_text_indent,
178 fmt_marker: dto.fmt_marker,
179 fmt_tab_positions: dto.fmt_tab_positions,
180 fmt_line_height: dto.fmt_line_height,
181 fmt_non_breakable_lines: dto.fmt_non_breakable_lines,
182 fmt_direction: dto.fmt_direction,
183 fmt_background_color: dto.fmt_background_color,
184 fmt_is_code_block: dto.fmt_is_code_block,
185 fmt_code_language: dto.fmt_code_language,
186 }
187 }
188}
189
190impl From<&CreateBlockDto> for Block {
191 fn from(dto: &CreateBlockDto) -> Self {
192 Block {
193 id: 0,
194 created_at: dto.created_at,
195 updated_at: dto.updated_at,
196 elements: dto.elements.clone(),
197 list: dto.list,
198 text_length: dto.text_length,
199 document_position: dto.document_position,
200 plain_text: dto.plain_text.clone(),
201 fmt_alignment: dto.fmt_alignment.clone(),
202 fmt_top_margin: dto.fmt_top_margin,
203 fmt_bottom_margin: dto.fmt_bottom_margin,
204 fmt_left_margin: dto.fmt_left_margin,
205 fmt_right_margin: dto.fmt_right_margin,
206 fmt_heading_level: dto.fmt_heading_level,
207 fmt_indent: dto.fmt_indent,
208 fmt_text_indent: dto.fmt_text_indent,
209 fmt_marker: dto.fmt_marker.clone(),
210 fmt_tab_positions: dto.fmt_tab_positions.clone(),
211 fmt_line_height: dto.fmt_line_height,
212 fmt_non_breakable_lines: dto.fmt_non_breakable_lines,
213 fmt_direction: dto.fmt_direction.clone(),
214 fmt_background_color: dto.fmt_background_color.clone(),
215 fmt_is_code_block: dto.fmt_is_code_block,
216 fmt_code_language: dto.fmt_code_language.clone(),
217 }
218 }
219}
220
221impl From<Block> for CreateBlockDto {
222 fn from(entity: Block) -> Self {
223 CreateBlockDto {
224 created_at: entity.created_at,
225 updated_at: entity.updated_at,
226 elements: entity.elements,
227 list: entity.list,
228 text_length: entity.text_length,
229 document_position: entity.document_position,
230 plain_text: entity.plain_text,
231 fmt_alignment: entity.fmt_alignment,
232 fmt_top_margin: entity.fmt_top_margin,
233 fmt_bottom_margin: entity.fmt_bottom_margin,
234 fmt_left_margin: entity.fmt_left_margin,
235 fmt_right_margin: entity.fmt_right_margin,
236 fmt_heading_level: entity.fmt_heading_level,
237 fmt_indent: entity.fmt_indent,
238 fmt_text_indent: entity.fmt_text_indent,
239 fmt_marker: entity.fmt_marker,
240 fmt_tab_positions: entity.fmt_tab_positions,
241 fmt_line_height: entity.fmt_line_height,
242 fmt_non_breakable_lines: entity.fmt_non_breakable_lines,
243 fmt_direction: entity.fmt_direction,
244 fmt_background_color: entity.fmt_background_color,
245 fmt_is_code_block: entity.fmt_is_code_block,
246 fmt_code_language: entity.fmt_code_language,
247 }
248 }
249}
250
251#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
252pub struct UpdateBlockDto {
253 pub id: EntityId,
254 pub created_at: chrono::DateTime<chrono::Utc>,
255 pub updated_at: chrono::DateTime<chrono::Utc>,
256 pub text_length: i64,
257 pub document_position: i64,
258 pub plain_text: String,
259 pub fmt_alignment: Option<Alignment>,
260 pub fmt_top_margin: Option<i64>,
261 pub fmt_bottom_margin: Option<i64>,
262 pub fmt_left_margin: Option<i64>,
263 pub fmt_right_margin: Option<i64>,
264 pub fmt_heading_level: Option<i64>,
265 pub fmt_indent: Option<i64>,
266 pub fmt_text_indent: Option<i64>,
267 pub fmt_marker: Option<MarkerType>,
268 pub fmt_tab_positions: Vec<i64>,
269 pub fmt_line_height: Option<i64>,
270 pub fmt_non_breakable_lines: Option<bool>,
271 pub fmt_direction: Option<TextDirection>,
272 pub fmt_background_color: Option<String>,
273 pub fmt_is_code_block: Option<bool>,
274 pub fmt_code_language: Option<String>,
275}
276
277impl From<UpdateBlockDto> for Block {
278 fn from(dto: UpdateBlockDto) -> Self {
279 Block {
280 id: dto.id,
281 created_at: dto.created_at,
282 updated_at: dto.updated_at,
283 text_length: dto.text_length,
284 document_position: dto.document_position,
285 plain_text: dto.plain_text,
286 fmt_alignment: dto.fmt_alignment,
287 fmt_top_margin: dto.fmt_top_margin,
288 fmt_bottom_margin: dto.fmt_bottom_margin,
289 fmt_left_margin: dto.fmt_left_margin,
290 fmt_right_margin: dto.fmt_right_margin,
291 fmt_heading_level: dto.fmt_heading_level,
292 fmt_indent: dto.fmt_indent,
293 fmt_text_indent: dto.fmt_text_indent,
294 fmt_marker: dto.fmt_marker,
295 fmt_tab_positions: dto.fmt_tab_positions,
296 fmt_line_height: dto.fmt_line_height,
297 fmt_non_breakable_lines: dto.fmt_non_breakable_lines,
298 fmt_direction: dto.fmt_direction,
299 fmt_background_color: dto.fmt_background_color,
300 fmt_is_code_block: dto.fmt_is_code_block,
301 fmt_code_language: dto.fmt_code_language,
302 elements: Default::default(),
303 list: Default::default(),
304 }
305 }
306}
307
308impl From<&UpdateBlockDto> for Block {
309 fn from(dto: &UpdateBlockDto) -> Self {
310 Block {
311 id: dto.id,
312 created_at: dto.created_at,
313 updated_at: dto.updated_at,
314 text_length: dto.text_length,
315 document_position: dto.document_position,
316 plain_text: dto.plain_text.clone(),
317 fmt_alignment: dto.fmt_alignment.clone(),
318 fmt_top_margin: dto.fmt_top_margin,
319 fmt_bottom_margin: dto.fmt_bottom_margin,
320 fmt_left_margin: dto.fmt_left_margin,
321 fmt_right_margin: dto.fmt_right_margin,
322 fmt_heading_level: dto.fmt_heading_level,
323 fmt_indent: dto.fmt_indent,
324 fmt_text_indent: dto.fmt_text_indent,
325 fmt_marker: dto.fmt_marker.clone(),
326 fmt_tab_positions: dto.fmt_tab_positions.clone(),
327 fmt_line_height: dto.fmt_line_height,
328 fmt_non_breakable_lines: dto.fmt_non_breakable_lines,
329 fmt_direction: dto.fmt_direction.clone(),
330 fmt_background_color: dto.fmt_background_color.clone(),
331 fmt_is_code_block: dto.fmt_is_code_block,
332 fmt_code_language: dto.fmt_code_language.clone(),
333 elements: Default::default(),
334 list: Default::default(),
335 }
336 }
337}
338
339impl From<Block> for UpdateBlockDto {
340 fn from(entity: Block) -> Self {
341 UpdateBlockDto {
342 id: entity.id,
343 created_at: entity.created_at,
344 updated_at: entity.updated_at,
345 text_length: entity.text_length,
346 document_position: entity.document_position,
347 plain_text: entity.plain_text,
348 fmt_alignment: entity.fmt_alignment,
349 fmt_top_margin: entity.fmt_top_margin,
350 fmt_bottom_margin: entity.fmt_bottom_margin,
351 fmt_left_margin: entity.fmt_left_margin,
352 fmt_right_margin: entity.fmt_right_margin,
353 fmt_heading_level: entity.fmt_heading_level,
354 fmt_indent: entity.fmt_indent,
355 fmt_text_indent: entity.fmt_text_indent,
356 fmt_marker: entity.fmt_marker,
357 fmt_tab_positions: entity.fmt_tab_positions,
358 fmt_line_height: entity.fmt_line_height,
359 fmt_non_breakable_lines: entity.fmt_non_breakable_lines,
360 fmt_direction: entity.fmt_direction,
361 fmt_background_color: entity.fmt_background_color,
362 fmt_is_code_block: entity.fmt_is_code_block,
363 fmt_code_language: entity.fmt_code_language,
364 }
365 }
366}
367
368impl From<BlockDto> for UpdateBlockDto {
369 fn from(dto: BlockDto) -> Self {
370 UpdateBlockDto {
371 id: dto.id,
372 created_at: dto.created_at,
373 updated_at: dto.updated_at,
374 text_length: dto.text_length,
375 document_position: dto.document_position,
376 plain_text: dto.plain_text,
377 fmt_alignment: dto.fmt_alignment,
378 fmt_top_margin: dto.fmt_top_margin,
379 fmt_bottom_margin: dto.fmt_bottom_margin,
380 fmt_left_margin: dto.fmt_left_margin,
381 fmt_right_margin: dto.fmt_right_margin,
382 fmt_heading_level: dto.fmt_heading_level,
383 fmt_indent: dto.fmt_indent,
384 fmt_text_indent: dto.fmt_text_indent,
385 fmt_marker: dto.fmt_marker,
386 fmt_tab_positions: dto.fmt_tab_positions,
387 fmt_line_height: dto.fmt_line_height,
388 fmt_non_breakable_lines: dto.fmt_non_breakable_lines,
389 fmt_direction: dto.fmt_direction,
390 fmt_background_color: dto.fmt_background_color,
391 fmt_is_code_block: dto.fmt_is_code_block,
392 fmt_code_language: dto.fmt_code_language,
393 }
394 }
395}
396pub use common::direct_access::block::BlockRelationshipField;
397
398#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
399pub struct BlockRelationshipDto {
400 pub id: EntityId,
401 pub field: BlockRelationshipField,
402 pub right_ids: Vec<EntityId>,
403}