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