Unified stack `GetValue` implementation
parent: tbd commit: 325f5af
1 | use ; |
2 | |
3 | use ; |
4 | use |
5 | , | UserAuthenticationToken
6 | , |
7 | |
8 | AuthenticationTokenRequest, Instance, RegisterAccountRequest, RepositoryCreateRequest, |
9 | , |
10 | , | ObjectBackend
11 | |
12 | Commit, DefaultBranch, Description, LatestCommit, Repository, |
13 | RepositoryCommitBeforeRequest, RepositoryDiff, RepositoryDiffPatchRequest, |
14 | RepositoryDiffRequest, RepositoryFile, RepositoryFileFromIdRequest, |
15 | RepositoryFileFromPathRequest, RepositoryFileInspectRequest, RepositoryInfoRequest, |
16 | RepositorySummary, RepositoryView, Visibility, |
17 | , |
18 | , |
19 | , |
20 | , |
21 | ; |
22 | use ; |
23 | |
24 | use DatabaseBackend; |
25 | |
26 | |
27 | object: &User, |
28 | _operation: UserRepositoriesRequest, |
29 | state: DatabaseBackend, |
30 | _operation_state: StackOperationState, |
31 | requester: , |
32 | |
33 | let object = object.clone; |
34 | |
35 | async move |
36 | let mut user_backend = state.user_backend.lock .await; |
37 | let repositories_response = user_backend |
38 | .repositories_for_user |
39 | .await |
40 | .map_err?; |
41 | drop; |
42 | let mut repositories_backend = state.repository_backend.lock .await; |
43 | |
44 | let mut repositories = vec!; |
45 | |
46 | for repository in repositories_response |
47 | if repositories_backend |
48 | .exists |
49 | .await |
50 | .map_err? |
51 | |
52 | repositories.push; |
53 | |
54 | |
55 | |
56 | Ok |
57 | |
58 | .boxed_local |
59 | |
60 | |
61 | |
62 | object: &User, |
63 | operation: , |
64 | state: DatabaseBackend, |
65 | |
66 | let object = object.clone; |
67 | |
68 | async move |
69 | let mut user_backend = state.user_backend.lock .await; |
70 | let value = user_backend |
71 | .get_value |
72 | .await |
73 | .map_err?; |
74 | |
75 | Ok |
76 | |
77 | .boxed_local |
78 | |
79 | |
80 | |
81 | object: &User, |
82 | operation: GetSetting, |
83 | state: DatabaseBackend, |
84 | |
85 | let object = object.clone; |
86 | |
87 | async move |
88 | let mut user_backend = state.user_backend.lock .await; |
89 | let value = user_backend |
90 | .get_setting |
91 | .await |
92 | .map_err?; |
93 | |
94 | Ok |
95 | |
96 | .boxed_local |
97 | |
98 | |
99 | |
100 | object: &Repository, |
101 | operation: RepositoryInfoRequest, |
102 | state: DatabaseBackend, |
103 | operation_state: StackOperationState, |
104 | backend: , |
105 | requester: , |
106 | |
107 | let object = object.clone; |
108 | |
109 | async move |
110 | let mut object = backend |
111 | . |
112 | .await |
113 | .unwrap; |
114 | let mut repository_backend = state.repository_backend.lock .await; |
115 | let tree = repository_backend |
116 | .repository_file_inspect |
117 | &requester, |
118 | object.object, |
119 | &RepositoryFileInspectRequest |
120 | extra_metadata: operation.extra_metadata, |
121 | path: operation.path, |
122 | rev: operation.rev.clone, |
123 | , |
124 | |
125 | .await |
126 | .map_err?; |
127 | drop; |
128 | |
129 | let info = RepositoryView |
130 | name: object.object .name.clone, |
131 | owner: object.object .owner.clone, |
132 | description: object. .await.ok, |
133 | visibility: object |
134 | . |
135 | .await |
136 | .map_err?, |
137 | default_branch: object |
138 | . |
139 | .await |
140 | .map_err?, |
141 | // 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. |
142 | latest_commit: object. .await.ok, |
143 | tree_rev: operation.rev, |
144 | tree, |
145 | ; |
146 | |
147 | Ok |
148 | |
149 | .boxed_local |
150 | |
151 | |
152 | |
153 | object: &Repository, |
154 | operation: RepositoryFileFromIdRequest, |
155 | state: DatabaseBackend, |
156 | operation_state: StackOperationState, |
157 | backend: , |
158 | |
159 | requester: , |
160 | |
161 | let object = object.clone; |
162 | |
163 | async move |
164 | let object = backend |
165 | . |
166 | .await |
167 | .unwrap; |
168 | |
169 | let mut repository_backend = state.repository_backend.lock .await; |
170 | let file = repository_backend |
171 | .repository_file_from_id |
172 | &requester, |
173 | object.object, |
174 | &RepositoryFileFromIdRequest, |
175 | |
176 | .await |
177 | .map_err?; |
178 | drop; |
179 | |
180 | Ok |
181 | |
182 | .boxed_local |
183 | |
184 | |
185 | |
186 | object: &Repository, |
187 | operation: RepositoryFileFromPathRequest, |
188 | state: DatabaseBackend, |
189 | operation_state: StackOperationState, |
190 | backend: , |
191 | requester: , |
192 | |
193 | let object = object.clone; |
194 | |
195 | async move |
196 | let object = backend |
197 | . |
198 | .await |
199 | .unwrap; |
200 | |
201 | let mut repository_backend = state.repository_backend.lock .await; |
202 | let file = repository_backend |
203 | .repository_file_from_path |
204 | &requester, |
205 | object.object, |
206 | &RepositoryFileFromPathRequest |
207 | rev: operation.rev, |
208 | path: operation.path, |
209 | , |
210 | |
211 | .await |
212 | .map_err?; |
213 | drop; |
214 | |
215 | Ok |
216 | |
217 | .boxed_local |
218 | |
219 | |
220 | |
221 | object: &Repository, |
222 | operation: RepositoryDiffRequest, |
223 | state: DatabaseBackend, |
224 | operation_state: StackOperationState, |
225 | backend: , |
226 | requester: , |
227 | |
228 | let object = object.clone; |
229 | |
230 | async move |
231 | let object = backend |
232 | . |
233 | .await |
234 | .unwrap; |
235 | |
236 | let mut repository_backend = state.repository_backend.lock .await; |
237 | let diff = repository_backend |
238 | .repository_diff |
239 | .await |
240 | .map_err?; |
241 | drop; |
242 | |
243 | Ok |
244 | |
245 | .boxed_local |
246 | |
247 | |
248 | |
249 | object: &Repository, |
250 | operation: RepositoryDiffPatchRequest, |
251 | state: DatabaseBackend, |
252 | operation_state: StackOperationState, |
253 | backend: , |
254 | requester: , |
255 | |
256 | let object = object.clone; |
257 | |
258 | async move |
259 | let object = backend |
260 | . |
261 | .await |
262 | .unwrap; |
263 | |
264 | let mut repository_backend = state.repository_backend.lock .await; |
265 | let patch = repository_backend |
266 | .repository_diff_patch |
267 | .await |
268 | .map_err?; |
269 | drop; |
270 | |
271 | Ok |
272 | |
273 | .boxed_local |
274 | |
275 | |
276 | |
277 | object: &Repository, |
278 | operation: RepositoryCommitBeforeRequest, |
279 | state: DatabaseBackend, |
280 | operation_state: StackOperationState, |
281 | backend: , |
282 | requester: , |
283 | |
284 | let object = object.clone; |
285 | |
286 | async move |
287 | let object = backend |
288 | . |
289 | .await |
290 | .unwrap; |
291 | |
292 | let mut repository_backend = state.repository_backend.lock .await; |
293 | let file = repository_backend |
294 | .repository_commit_before |
295 | .await |
296 | .map_err?; |
297 | drop; |
298 | |
299 | Ok |
300 | |
301 | .boxed_local |
302 | |
303 | |
304 | |
305 | object: &Repository, |
306 | operation: , |
307 | state: DatabaseBackend, |
308 | |
309 | let object = object.clone; |
310 | |
311 | async move |
312 | let mut repository_backend = state.repository_backend.lock .await; |
313 | let value = repository_backend |
314 | .get_value |
315 | .await |
316 | .map_err |
317 | Internal |
318 | ?; |
319 | |
320 | Ok |
321 | |
322 | .boxed_local |
323 | |
324 | |
325 | |
326 | object: &Repository, |
327 | operation: GetSetting, |
328 | state: DatabaseBackend, |
329 | |
330 | let object = object.clone; |
331 | |
332 | async move |
333 | let mut repository_backend = state.repository_backend.lock .await; |
334 | let value = repository_backend |
335 | .get_setting |
336 | .await |
337 | .map_err?; |
338 | |
339 | Ok |
340 | |
341 | .boxed_local |
342 | |
343 | |
344 | |
345 | object: &Instance, |
346 | operation: AuthenticationTokenRequest, |
347 | state: DatabaseBackend, |
348 | // Authorizes the request for SAME-INSTANCE |
349 | _authorized_instance: AuthorizedInstance, |
350 | |
351 | let object = object.clone; |
352 | async move |
353 | let mut backend = state.user_backend.lock .await; |
354 | |
355 | backend |
356 | .login |
357 | .await |
358 | .map_err |
359 | |
360 | .boxed_local |
361 | |
362 | |
363 | |
364 | _object: &Instance, |
365 | operation: RegisterAccountRequest, |
366 | state: DatabaseBackend, |
367 | // Authorizes the request for SAME-INSTANCE |
368 | _authorized_instance: AuthorizedInstance, |
369 | |
370 | async move |
371 | let mut backend = state.user_backend.lock .await; |
372 | |
373 | backend |
374 | .register |
375 | .await |
376 | .map_err |
377 | |
378 | .boxed_local |
379 | |
380 | |
381 | |
382 | _object: &Instance, |
383 | operation: RepositoryCreateRequest, |
384 | state: DatabaseBackend, |
385 | requester: AuthenticatedUser, |
386 | // Authorizes the request for SAME-INSTANCE |
387 | _authorized_instance: AuthorizedInstance, |
388 | |
389 | async move |
390 | let mut backend = state.repository_backend.lock .await; |
391 | |
392 | backend |
393 | .create_repository |
394 | .await |
395 | .map_err |
396 | |
397 | .boxed_local |
398 | |
399 | |
400 | |
401 | object: &User, |
402 | operation: , |
403 | state: DatabaseBackend, |
404 | // _requester: AuthorizedUser, |
405 | |
406 | let object = object.clone; |
407 | |
408 | async move |
409 | let mut backend = state.user_backend.lock .await; |
410 | |
411 | let raw_value = backend |
412 | .get_value |
413 | .await |
414 | .map_err?; |
415 | |
416 | Ok |
417 | .map_err? |
418 | |
419 | .boxed_local |
420 | |
421 | |
422 | |
423 | object: &User, |
424 | operation: , |
425 | state: DatabaseBackend, |
426 | |
427 | let object = object.clone; |
428 | |
429 | async move |
430 | let mut backend = state.user_backend.lock .await; |
431 | |
432 | let raw_value = backend |
433 | .get_value |
434 | .await |
435 | .map_err?; |
436 | |
437 | Ok |
438 | .map_err? |
439 | |
440 | .boxed_local |
441 | |
442 | |
443 | |
444 | object: &Repository, |
445 | operation: , |
446 | state: DatabaseBackend, |
447 | |
448 | let object = object.clone; |
449 | |
450 | async move |
451 | let mut backend = state.repository_backend.lock .await; |
452 | |
453 | let raw_value = backend |
454 | .get_value |
455 | .await |
456 | .map_err?; |
457 | |
458 | Ok |
459 | .map_err? |
460 | |
461 | .boxed_local |
462 | |
463 | |
464 | |
465 | object: &Repository, |
466 | operation: , |
467 | state: DatabaseBackend, |
468 | |
469 | let object = object.clone; |
470 | |
471 | async move |
472 | let mut backend = state.repository_backend.lock .await; |
473 | |
474 | let raw_value = backend |
475 | .get_value |
476 | .await |
477 | .map_err?; |
478 | |
479 | Ok |
480 | .map_err? |
481 | |
482 | .boxed_local |
483 | |
484 | |
485 | |
486 | object: &Repository, |
487 | operation: , |
488 | state: DatabaseBackend, |
489 | |
490 | let object = object.clone; |
491 | |
492 | async move |
493 | let mut backend = state.repository_backend.lock .await; |
494 | |
495 | let raw_value = backend |
496 | .get_value |
497 | .await |
498 | .map_err?; |
499 | |
500 | Ok |
501 | .map_err? |
502 | |
503 | .boxed_local |
504 | |
505 | |
506 | |
507 | object: &Repository, |
508 | operation: , |
509 | state: DatabaseBackend, |
510 | |
511 | let object = object.clone; |
512 | |
513 | async move |
514 | let mut backend = state.repository_backend.lock .await; |
515 | |
516 | let raw_value = backend |
517 | .get_value |
518 | .await |
519 | .map_err?; |
520 | |
521 | Ok |
522 | .map_err? |
523 | |
524 | .boxed_local |
525 | |
526 |