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