1use common::entities::Document;
4pub use common::entities::TextDirection;
5pub use common::entities::WrapMode;
6use common::types::EntityId;
7use serde::{Deserialize, Serialize};
8use std::convert::From;
9
10#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
11pub struct DocumentDto {
12 pub id: EntityId,
13 pub created_at: chrono::DateTime<chrono::Utc>,
14 pub updated_at: chrono::DateTime<chrono::Utc>,
15 pub title: String,
16 pub frames: Vec<EntityId>,
17 pub text_direction: TextDirection,
18 pub default_wrap_mode: WrapMode,
19 pub default_language: Option<String>,
20 pub resources: Vec<EntityId>,
21 pub lists: Vec<EntityId>,
22 pub tables: Vec<EntityId>,
23 pub character_count: i64,
24 pub block_count: i64,
25}
26
27impl From<DocumentDto> for Document {
28 fn from(dto: DocumentDto) -> Self {
29 Document {
30 id: dto.id,
31 created_at: dto.created_at,
32 updated_at: dto.updated_at,
33 title: dto.title,
34 frames: dto.frames,
35 text_direction: dto.text_direction,
36 default_wrap_mode: dto.default_wrap_mode,
37 default_language: dto.default_language,
38 resources: dto.resources,
39 lists: dto.lists,
40 tables: dto.tables,
41 character_count: dto.character_count,
42 block_count: dto.block_count,
43 }
44 }
45}
46
47impl From<&DocumentDto> for Document {
48 fn from(dto: &DocumentDto) -> Self {
49 Document {
50 id: dto.id,
51 created_at: dto.created_at,
52 updated_at: dto.updated_at,
53 title: dto.title.clone(),
54 frames: dto.frames.clone(),
55 text_direction: dto.text_direction.clone(),
56 default_wrap_mode: dto.default_wrap_mode.clone(),
57 default_language: dto.default_language.clone(),
58 resources: dto.resources.clone(),
59 lists: dto.lists.clone(),
60 tables: dto.tables.clone(),
61 character_count: dto.character_count,
62 block_count: dto.block_count,
63 }
64 }
65}
66
67impl From<Document> for DocumentDto {
68 fn from(entity: Document) -> Self {
69 DocumentDto {
70 id: entity.id,
71 created_at: entity.created_at,
72 updated_at: entity.updated_at,
73 title: entity.title,
74 frames: entity.frames,
75 text_direction: entity.text_direction,
76 default_wrap_mode: entity.default_wrap_mode,
77 default_language: entity.default_language,
78 resources: entity.resources,
79 lists: entity.lists,
80 tables: entity.tables,
81 character_count: entity.character_count,
82 block_count: entity.block_count,
83 }
84 }
85}
86
87#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
88pub struct CreateDocumentDto {
89 pub created_at: chrono::DateTime<chrono::Utc>,
90 pub updated_at: chrono::DateTime<chrono::Utc>,
91 pub title: String,
92 pub frames: Vec<EntityId>,
93 pub text_direction: TextDirection,
94 pub default_wrap_mode: WrapMode,
95 pub default_language: Option<String>,
96 pub resources: Vec<EntityId>,
97 pub lists: Vec<EntityId>,
98 pub tables: Vec<EntityId>,
99 pub character_count: i64,
100 pub block_count: i64,
101}
102
103impl From<CreateDocumentDto> for Document {
104 fn from(dto: CreateDocumentDto) -> Self {
105 Document {
106 id: 0,
107 created_at: dto.created_at,
108 updated_at: dto.updated_at,
109 title: dto.title,
110 frames: dto.frames,
111 text_direction: dto.text_direction,
112 default_wrap_mode: dto.default_wrap_mode,
113 default_language: dto.default_language,
114 resources: dto.resources,
115 lists: dto.lists,
116 tables: dto.tables,
117 character_count: dto.character_count,
118 block_count: dto.block_count,
119 }
120 }
121}
122
123impl From<&CreateDocumentDto> for Document {
124 fn from(dto: &CreateDocumentDto) -> Self {
125 Document {
126 id: 0,
127 created_at: dto.created_at,
128 updated_at: dto.updated_at,
129 title: dto.title.clone(),
130 frames: dto.frames.clone(),
131 text_direction: dto.text_direction.clone(),
132 default_wrap_mode: dto.default_wrap_mode.clone(),
133 default_language: dto.default_language.clone(),
134 resources: dto.resources.clone(),
135 lists: dto.lists.clone(),
136 tables: dto.tables.clone(),
137 character_count: dto.character_count,
138 block_count: dto.block_count,
139 }
140 }
141}
142
143impl From<Document> for CreateDocumentDto {
144 fn from(entity: Document) -> Self {
145 CreateDocumentDto {
146 created_at: entity.created_at,
147 updated_at: entity.updated_at,
148 title: entity.title,
149 frames: entity.frames,
150 text_direction: entity.text_direction,
151 default_wrap_mode: entity.default_wrap_mode,
152 default_language: entity.default_language,
153 resources: entity.resources,
154 lists: entity.lists,
155 tables: entity.tables,
156 character_count: entity.character_count,
157 block_count: entity.block_count,
158 }
159 }
160}
161
162#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
163pub struct UpdateDocumentDto {
164 pub id: EntityId,
165 pub created_at: chrono::DateTime<chrono::Utc>,
166 pub updated_at: chrono::DateTime<chrono::Utc>,
167 pub title: String,
168 pub text_direction: TextDirection,
169 pub default_wrap_mode: WrapMode,
170 pub default_language: Option<String>,
171 pub character_count: i64,
172 pub block_count: i64,
173}
174
175impl From<UpdateDocumentDto> for Document {
176 fn from(dto: UpdateDocumentDto) -> Self {
177 Document {
178 id: dto.id,
179 created_at: dto.created_at,
180 updated_at: dto.updated_at,
181 title: dto.title,
182 text_direction: dto.text_direction,
183 default_wrap_mode: dto.default_wrap_mode,
184 default_language: dto.default_language,
185 character_count: dto.character_count,
186 block_count: dto.block_count,
187 frames: Default::default(),
188 resources: Default::default(),
189 lists: Default::default(),
190 tables: Default::default(),
191 }
192 }
193}
194
195impl From<&UpdateDocumentDto> for Document {
196 fn from(dto: &UpdateDocumentDto) -> Self {
197 Document {
198 id: dto.id,
199 created_at: dto.created_at,
200 updated_at: dto.updated_at,
201 title: dto.title.clone(),
202 text_direction: dto.text_direction.clone(),
203 default_wrap_mode: dto.default_wrap_mode.clone(),
204 default_language: dto.default_language.clone(),
205 character_count: dto.character_count,
206 block_count: dto.block_count,
207 frames: Default::default(),
208 resources: Default::default(),
209 lists: Default::default(),
210 tables: Default::default(),
211 }
212 }
213}
214
215impl From<Document> for UpdateDocumentDto {
216 fn from(entity: Document) -> Self {
217 UpdateDocumentDto {
218 id: entity.id,
219 created_at: entity.created_at,
220 updated_at: entity.updated_at,
221 title: entity.title,
222 text_direction: entity.text_direction,
223 default_wrap_mode: entity.default_wrap_mode,
224 default_language: entity.default_language,
225 character_count: entity.character_count,
226 block_count: entity.block_count,
227 }
228 }
229}
230
231impl From<DocumentDto> for UpdateDocumentDto {
232 fn from(dto: DocumentDto) -> Self {
233 UpdateDocumentDto {
234 id: dto.id,
235 created_at: dto.created_at,
236 updated_at: dto.updated_at,
237 title: dto.title,
238 text_direction: dto.text_direction,
239 default_wrap_mode: dto.default_wrap_mode,
240 default_language: dto.default_language,
241 character_count: dto.character_count,
242 block_count: dto.block_count,
243 }
244 }
245}
246pub use common::direct_access::document::DocumentRelationshipField;
247
248#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
249pub struct DocumentRelationshipDto {
250 pub id: EntityId,
251 pub field: DocumentRelationshipField,
252 pub right_ids: Vec<EntityId>,
253}