Fix handling stack
parent: tbd commit: c53b026
1 | use ; |
2 | |
3 | use ; |
4 | use |
5 | , |
6 | , |
7 | , | ObjectBackend
8 | , |
9 | |
10 | DefaultBranch, Description, LatestCommit, Repository, RepositoryFileInspectRequest, |
11 | RepositoryInfoRequest, RepositorySummary, RepositoryView, Visibility, |
12 | , |
13 | , |
14 | , |
15 | , |
16 | ; |
17 | |
18 | use DatabaseBackend; |
19 | |
20 | |
21 | |
22 | O: GiteratedObject, |
23 | D: GiteratedOperation<O>, |
24 | S: Send + Sync + Clone, |
25 | > |
26 | |
27 | ; |
28 | ; |
29 | |
30 | async |
31 | &self, |
32 | object: &O, |
33 | operation: D, |
34 | state: S, |
35 | ; |
36 | |
37 | |
38 | |
39 | |
40 | |
41 | F: FnMut( |
42 | &O, |
43 | D, |
44 | S, |
45 | ) -> |
46 | , |
47 | > + Send |
48 | + Sync |
49 | + Clone, |
50 | O: GiteratedObject + Send + Sync, |
51 | D: + 'static, |
52 | : Send, | Failure
53 | S: Send + Sync + Clone + 'static, |
54 | |
55 | |
56 | operation_name |
57 | |
58 | |
59 | |
60 | object_name |
61 | |
62 | |
63 | async |
64 | &self, |
65 | object: &O, |
66 | operation: D, |
67 | state: S, |
68 | |
69 | self.clone .await |
70 | |
71 | |
72 | |
73 | |
74 | |
75 | dyn Fn( |
76 | AnyObject, |
77 | AnyOperation, |
78 | S, |
79 | ) |
80 | |
81 | + Send |
82 | + Sync, |
83 | >, |
84 | ); |
85 | |
86 | |
87 | |
88 | O: GiteratedObject + Send + Sync, |
89 | D: + 'static, |
90 | F: + Send + Sync + 'static + Clone, |
91 | > |
92 | handler: F, |
93 | |
94 | let handler = new; |
95 | Self |
96 | let handler = handler.clone; |
97 | async move |
98 | let handler = handler.clone; |
99 | let object: O = from_object_str .unwrap; |
100 | let operation: D = from_value .unwrap; |
101 | |
102 | let result = handler.handle .await; |
103 | result |
104 | .map |
105 | .map_err |
106 | => | Operation
107 | Operation |
108 | |
109 | => Internal, | Internal
110 | => Unhandled, | Unhandled
111 | |
112 | |
113 | .boxed |
114 | |
115 | |
116 | |
117 | async |
118 | &mut self, |
119 | object: AnyObject, |
120 | operation: AnyOperation, |
121 | state: S, |
122 | |
123 | self.0 .await |
124 | |
125 | |
126 | |
127 | |
128 | object: &User, |
129 | _operation: UserRepositoriesRequest, |
130 | state: DatabaseBackend, |
131 | |
132 | let object = object.clone; |
133 | |
134 | async move |
135 | let mut user_backend = state.user_backend.lock .await; |
136 | let repositories = user_backend |
137 | .repositories_for_user |
138 | .await |
139 | .map_err?; |
140 | |
141 | Ok |
142 | |
143 | .boxed |
144 | |
145 | |
146 | |
147 | object: &User, |
148 | operation: , |
149 | state: DatabaseBackend, |
150 | |
151 | let object = object.clone; |
152 | |
153 | async move |
154 | let mut user_backend = state.user_backend.lock .await; |
155 | let value = user_backend |
156 | .get_value |
157 | .await |
158 | .map_err?; |
159 | |
160 | Ok |
161 | |
162 | .boxed |
163 | |
164 | |
165 | |
166 | object: &User, |
167 | operation: , |
168 | state: DatabaseBackend, |
169 | |
170 | let object = object.clone; |
171 | |
172 | async move |
173 | let mut user_backend = state.user_backend.lock .await; |
174 | let value = user_backend |
175 | .get_setting |
176 | .await |
177 | .map_err?; |
178 | |
179 | Ok |
180 | |
181 | .boxed |
182 | |
183 | |
184 | |
185 | object: &User, |
186 | operation: , |
187 | state: DatabaseBackend, |
188 | |
189 | let object = object.clone; |
190 | |
191 | async move |
192 | let mut user_backend = state.user_backend.lock .await; |
193 | let value = user_backend |
194 | .write_setting |
195 | .await |
196 | .map_err?; |
197 | |
198 | Ok |
199 | |
200 | .boxed |
201 | |
202 | |
203 | |
204 | object: &Repository, |
205 | operation: RepositoryInfoRequest, |
206 | state: DatabaseBackend, |
207 | |
208 | let object = object.clone; |
209 | |
210 | async move |
211 | let mut object = state |
212 | . |
213 | .await |
214 | .unwrap; |
215 | |
216 | let mut repository_backend = state.repository_backend.lock .await; |
217 | let tree = repository_backend |
218 | .repository_file_inspect |
219 | None, |
220 | object.object, |
221 | &RepositoryFileInspectRequest |
222 | extra_metadata: operation.extra_metadata, |
223 | path: operation.path, |
224 | rev: operation.rev.clone, |
225 | , |
226 | |
227 | .await |
228 | .map_err?; |
229 | drop; |
230 | |
231 | let _visibility = object. .await.map_err |
232 | Internal |
233 | ?; |
234 | let _default_branch = object. .await.map_err |
235 | Internal |
236 | ?; |
237 | |
238 | let info = RepositoryView |
239 | name: object.object .name.clone, |
240 | owner: object.object .owner.clone, |
241 | description: object. .await.ok, |
242 | visibility: object |
243 | . |
244 | .await |
245 | .map_err?, |
246 | default_branch: object |
247 | . |
248 | .await |
249 | .map_err?, |
250 | // 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. |
251 | latest_commit: object. .await.ok, |
252 | tree_rev: operation.rev, |
253 | tree, |
254 | ; |
255 | |
256 | Ok |
257 | |
258 | .boxed |
259 | |
260 | |
261 | |
262 | object: &Repository, |
263 | operation: , |
264 | state: DatabaseBackend, |
265 | |
266 | let object = object.clone; |
267 | |
268 | async move |
269 | let mut repository_backend = state.repository_backend.lock .await; |
270 | let value = repository_backend |
271 | .get_value |
272 | .await |
273 | .map_err |
274 | Internal |
275 | ?; |
276 | |
277 | Ok |
278 | |
279 | .boxed |
280 | |
281 | |
282 | |
283 | object: &Repository, |
284 | operation: , |
285 | state: DatabaseBackend, |
286 | |
287 | let object = object.clone; |
288 | |
289 | async move |
290 | let mut repository_backend = state.repository_backend.lock .await; |
291 | let value = repository_backend |
292 | .get_setting |
293 | .await |
294 | .map_err?; |
295 | |
296 | Ok |
297 | |
298 | .boxed |
299 | |
300 | |
301 | |
302 | object: &Repository, |
303 | operation: , |
304 | state: DatabaseBackend, |
305 | |
306 | let object = object.clone; |
307 | |
308 | async move |
309 | let mut repository_backend = state.repository_backend.lock .await; |
310 | let value = repository_backend |
311 | .write_setting |
312 | .await |
313 | .map_err?; |
314 | |
315 | Ok |
316 | |
317 | .boxed |
318 | |
319 | |
320 | |
321 | operations: , |
322 | |
323 | |
324 | |
325 | |
326 | Self |
327 | operations: new, |
328 | |
329 | |
330 | |
331 | |
332 | |
333 | |
334 | O: GiteratedObject + Send + Sync, |
335 | D: + 'static, |
336 | H: + Send + Sync + 'static + Clone, |
337 | > |
338 | &mut self, |
339 | handler: H, |
340 | |
341 | let operation_name = handler.operation_name .to_string; |
342 | |
343 | let wrapped = new; |
344 | |
345 | self.operations.insert; |
346 | |
347 | self |
348 | |
349 | |
350 | pub async |
351 | &mut self, |
352 | object: &O, |
353 | operation_name: &str, |
354 | operation: AnyOperation, |
355 | state: S, |
356 | |
357 | if let Some = self.operations.get_mut |
358 | handler |
359 | .handle |
360 | .await |
361 | else |
362 | Err |
363 | "unknown operation: {}" |
364 | operation_name |
365 | ) |
366 | |
367 | |
368 | |
369 |