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