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