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