Re-expose Operation State in generics.
This is the worst code I have ever written. I hate the way this changes everything. ugh.
parent: tbd commit: 90db3e2
1 | use |
2 | , | UserAuthenticationToken
3 | , |
4 | |
5 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
6 | , |
7 | , | ObjectBackend
8 | |
9 | Commit, DefaultBranch, Description, LatestCommit, Repository, RepositoryBranch, |
10 | RepositoryBranchesRequest, RepositoryCommitBeforeRequest, RepositoryCommitFromIdRequest, |
11 | RepositoryDiff, RepositoryDiffPatchRequest, RepositoryDiffRequest, RepositoryFile, |
12 | RepositoryFileFromIdRequest, RepositoryFileFromPathRequest, RepositoryFileInspectRequest, |
13 | RepositoryInfoRequest, RepositoryLastCommitOfFileRequest, RepositoryStatistics, |
14 | RepositoryStatisticsRequest, RepositorySummary, RepositoryView, Visibility, |
15 | , |
16 | , |
17 | ; |
18 | use ; |
19 | |
20 | use DatabaseBackend; |
21 | |
22 | pub async |
23 | object: User, |
24 | _operation: UserRepositoriesRequest, |
25 | state: DatabaseBackend, |
26 | OperationState | : ,
27 | requester: , |
28 | |
29 | let object = object.clone; |
30 | |
31 | let mut user_backend = state.user_backend.lock .await; |
32 | let repositories_response = user_backend |
33 | .repositories_for_user |
34 | .await |
35 | .as_internal_error?; |
36 | drop; |
37 | let mut repositories_backend = state.repository_backend.lock .await; |
38 | |
39 | let mut repositories = vec!; |
40 | |
41 | for repository in repositories_response |
42 | if repositories_backend |
43 | .exists |
44 | .await |
45 | .as_internal_error? |
46 | |
47 | repositories.push; |
48 | |
49 | |
50 | |
51 | Ok |
52 | |
53 | |
54 | pub async |
55 | object: Repository, |
56 | operation: RepositoryInfoRequest, |
57 | state: DatabaseBackend, |
58 | OperationState | : ,
59 | backend: GiteratedStack, |
60 | requester: , |
61 | |
62 | info!; |
63 | let mut object = backend |
64 | . |
65 | .await |
66 | .unwrap; |
67 | let mut repository_backend = state.repository_backend.lock .await; |
68 | let tree = repository_backend |
69 | .repository_file_inspect |
70 | &requester, |
71 | object.object, |
72 | &RepositoryFileInspectRequest |
73 | extra_metadata: operation.extra_metadata, |
74 | path: operation.path.clone, |
75 | rev: operation.rev.clone, |
76 | , |
77 | |
78 | .await |
79 | .as_internal_error?; |
80 | |
81 | let statistics = repository_backend |
82 | .repository_get_statistics |
83 | &requester, |
84 | object.object, |
85 | &RepositoryStatisticsRequest |
86 | rev: operation.rev.clone, |
87 | , |
88 | |
89 | .await |
90 | .as_internal_error?; |
91 | drop; |
92 | |
93 | let info = RepositoryView |
94 | name: object.object .name.clone, |
95 | owner: object.object .owner.clone, |
96 | description: object. .await.ok, |
97 | visibility: object |
98 | . |
99 | .await |
100 | .as_internal_error?, |
101 | default_branch: object |
102 | . |
103 | .await |
104 | .as_internal_error?, |
105 | // TODO: Can't be a simple get function, this needs to be returned alongside the tree as this differs depending on the rev and path. |
106 | latest_commit: object. .await.ok, |
107 | stats: statistics, |
108 | tree_rev: operation.rev.clone, |
109 | tree, |
110 | ; |
111 | |
112 | Ok |
113 | |
114 | |
115 | pub async |
116 | object: Repository, |
117 | operation: RepositoryStatisticsRequest, |
118 | state: DatabaseBackend, |
119 | OperationState | : ,
120 | backend: GiteratedStack, |
121 | requester: , |
122 | |
123 | let object = backend |
124 | . |
125 | .await |
126 | .unwrap; |
127 | |
128 | let mut repository_backend = state.repository_backend.lock .await; |
129 | let statistics = repository_backend |
130 | .repository_get_statistics |
131 | &requester, |
132 | object.object, |
133 | &RepositoryStatisticsRequest |
134 | rev: operation.rev.clone, |
135 | , |
136 | |
137 | .await |
138 | .as_internal_error?; |
139 | drop; |
140 | |
141 | Ok |
142 | |
143 | |
144 | pub async |
145 | object: Repository, |
146 | operation: RepositoryBranchesRequest, |
147 | state: DatabaseBackend, |
148 | OperationState | : ,
149 | backend: GiteratedStack, |
150 | requester: , |
151 | |
152 | let object = backend |
153 | . |
154 | .await |
155 | .unwrap; |
156 | |
157 | let mut repository_backend = state.repository_backend.lock .await; |
158 | let branches = repository_backend |
159 | .repository_get_branches |
160 | .await |
161 | .as_internal_error?; |
162 | drop; |
163 | |
164 | Ok |
165 | |
166 | |
167 | pub async |
168 | object: Repository, |
169 | operation: RepositoryFileFromIdRequest, |
170 | state: DatabaseBackend, |
171 | OperationState | : ,
172 | backend: GiteratedStack, |
173 | |
174 | requester: , |
175 | |
176 | let object = backend |
177 | . |
178 | .await |
179 | .unwrap; |
180 | |
181 | let mut repository_backend = state.repository_backend.lock .await; |
182 | let file = repository_backend |
183 | .repository_file_from_id |
184 | &requester, |
185 | object.object, |
186 | &RepositoryFileFromIdRequest, |
187 | |
188 | .await |
189 | .as_internal_error?; |
190 | drop; |
191 | |
192 | Ok |
193 | |
194 | |
195 | pub async |
196 | object: Repository, |
197 | operation: RepositoryFileFromPathRequest, |
198 | state: DatabaseBackend, |
199 | OperationState | : ,
200 | backend: GiteratedStack, |
201 | requester: , |
202 | |
203 | let object = backend |
204 | . |
205 | .await |
206 | .unwrap; |
207 | |
208 | let mut repository_backend = state.repository_backend.lock .await; |
209 | let file = repository_backend |
210 | .repository_file_from_path |
211 | &requester, |
212 | object.object, |
213 | &RepositoryFileFromPathRequest |
214 | rev: operation.rev.clone, |
215 | path: operation.path.clone, |
216 | , |
217 | |
218 | .await |
219 | .as_internal_error?; |
220 | drop; |
221 | |
222 | Ok |
223 | |
224 | |
225 | pub async |
226 | object: Repository, |
227 | operation: RepositoryLastCommitOfFileRequest, |
228 | state: DatabaseBackend, |
229 | OperationState | : ,
230 | backend: GiteratedStack, |
231 | requester: , |
232 | |
233 | let object = backend |
234 | . |
235 | .await |
236 | .unwrap; |
237 | |
238 | let mut repository_backend = state.repository_backend.lock .await; |
239 | let commit = repository_backend |
240 | .repository_last_commit_of_file |
241 | &requester, |
242 | object.object, |
243 | &RepositoryLastCommitOfFileRequest |
244 | start_commit: operation.start_commit.clone, |
245 | path: operation.path.clone, |
246 | , |
247 | |
248 | .await |
249 | .as_internal_error?; |
250 | drop; |
251 | |
252 | Ok |
253 | |
254 | |
255 | pub async |
256 | object: Repository, |
257 | operation: RepositoryCommitFromIdRequest, |
258 | state: DatabaseBackend, |
259 | OperationState | : ,
260 | backend: GiteratedStack, |
261 | requester: , |
262 | |
263 | let object = backend |
264 | . |
265 | .await |
266 | .unwrap; |
267 | |
268 | let mut repository_backend = state.repository_backend.lock .await; |
269 | let commit = repository_backend |
270 | .repository_commit_from_id |
271 | &requester, |
272 | object.object, |
273 | &RepositoryCommitFromIdRequest, |
274 | |
275 | .await |
276 | .as_internal_error?; |
277 | drop; |
278 | |
279 | Ok |
280 | |
281 | |
282 | pub async |
283 | object: Repository, |
284 | operation: RepositoryDiffRequest, |
285 | state: DatabaseBackend, |
286 | OperationState | : ,
287 | backend: GiteratedStack, |
288 | requester: , |
289 | |
290 | let object = backend |
291 | . |
292 | .await |
293 | .unwrap; |
294 | |
295 | let mut repository_backend = state.repository_backend.lock .await; |
296 | let diff = repository_backend |
297 | .repository_diff |
298 | .await |
299 | .as_internal_error?; |
300 | drop; |
301 | |
302 | Ok |
303 | |
304 | |
305 | pub async |
306 | object: Repository, |
307 | operation: RepositoryDiffPatchRequest, |
308 | state: DatabaseBackend, |
309 | OperationState | : ,
310 | backend: GiteratedStack, |
311 | requester: , |
312 | |
313 | let object = backend |
314 | . |
315 | .await |
316 | .unwrap; |
317 | |
318 | let mut repository_backend = state.repository_backend.lock .await; |
319 | let patch = repository_backend |
320 | .repository_diff_patch |
321 | .await |
322 | .as_internal_error?; |
323 | drop; |
324 | |
325 | Ok |
326 | |
327 | |
328 | pub async |
329 | object: Repository, |
330 | operation: RepositoryCommitBeforeRequest, |
331 | state: DatabaseBackend, |
332 | OperationState | : ,
333 | backend: GiteratedStack, |
334 | requester: , |
335 | |
336 | let object = backend |
337 | . |
338 | .await |
339 | .unwrap; |
340 | |
341 | let mut repository_backend = state.repository_backend.lock .await; |
342 | let file = repository_backend |
343 | .repository_commit_before |
344 | .await |
345 | .as_internal_error?; |
346 | drop; |
347 | |
348 | Ok |
349 | |
350 | |
351 | pub async |
352 | object: Instance, |
353 | operation: AuthenticationTokenRequest, |
354 | state: DatabaseBackend, |
355 | OperationState | : ,
356 | // Authorizes the request for SAME-INSTANCE |
357 | // _authorized_instance: AuthorizedInstance, |
358 | |
359 | let mut backend = state.user_backend.lock .await; |
360 | |
361 | backend |
362 | .login |
363 | .await |
364 | .as_internal_error |
365 | |
366 | |
367 | pub async |
368 | _object: Instance, |
369 | operation: RegisterAccountRequest, |
370 | state: DatabaseBackend, |
371 | OperationState// Authorizes the request for SAME-INSTANCE | : ,
372 | // _authorized_instance: AuthorizedInstance, |
373 | |
374 | let mut backend = state.user_backend.lock .await; |
375 | |
376 | backend |
377 | .register |
378 | .await |
379 | .as_internal_error |
380 | |
381 | |
382 | pub async |
383 | _object: Instance, |
384 | operation: RepositoryCreateRequest, |
385 | state: DatabaseBackend, |
386 | OperationState | : ,
387 | requester: AuthenticatedUser, |
388 | // Authorizes the request for SAME-INSTANCE |
389 | // _authorized_instance: AuthorizedInstance, |
390 | |
391 | let mut backend = state.repository_backend.lock .await; |
392 | |
393 | backend |
394 | .create_repository |
395 | .await |
396 | .as_internal_error |
397 | |
398 | |
399 | pub async |
400 | _repository: Repository, |
401 | _state: DatabaseBackend, |
402 | OperationState | : ,
403 | |
404 | Ok |
405 | |
406 |