@@ -17,7 +17,7 @@ pub mod responses;
17
17
pub mod templates;
18
18
pub mod utils;
19
19
20
- use guards:: Cluster ;
20
+ use guards:: { Cluster , ConnectedCluster } ;
21
21
use responses:: { BadRequest , Error , ResponseOk } ;
22
22
use templates:: {
23
23
components:: StaticNav , DeploymentsTab , Layout , ModelsTab , NotebooksTab , ProjectsTab ,
@@ -47,7 +47,7 @@ pub struct Context {
47
47
}
48
48
49
49
#[ get( "/projects" ) ]
50
- pub async fn project_index ( cluster : & Cluster ) -> Result < ResponseOk , Error > {
50
+ pub async fn project_index ( cluster : ConnectedCluster < ' _ > ) -> Result < ResponseOk , Error > {
51
51
Ok ( ResponseOk (
52
52
templates:: Projects {
53
53
projects : models:: Project :: all ( cluster. pool ( ) ) . await ?,
@@ -58,7 +58,7 @@ pub async fn project_index(cluster: &Cluster) -> Result<ResponseOk, Error> {
58
58
}
59
59
60
60
#[ get( "/projects/<id>" ) ]
61
- pub async fn project_get ( cluster : & Cluster , id : i64 ) -> Result < ResponseOk , Error > {
61
+ pub async fn project_get ( cluster : ConnectedCluster < ' _ > , id : i64 ) -> Result < ResponseOk , Error > {
62
62
let project = models:: Project :: get_by_id ( cluster. pool ( ) , id) . await ?;
63
63
let models = models:: Model :: get_by_project_id ( cluster. pool ( ) , id) . await ?;
64
64
@@ -70,7 +70,7 @@ pub async fn project_get(cluster: &Cluster, id: i64) -> Result<ResponseOk, Error
70
70
}
71
71
72
72
#[ get( "/notebooks" ) ]
73
- pub async fn notebook_index ( cluster : & Cluster ) -> Result < ResponseOk , Error > {
73
+ pub async fn notebook_index ( cluster : ConnectedCluster < ' _ > ) -> Result < ResponseOk , Error > {
74
74
Ok ( ResponseOk (
75
75
templates:: Notebooks {
76
76
notebooks : models:: Notebook :: all ( & cluster. pool ( ) ) . await ?,
@@ -94,7 +94,10 @@ pub async fn notebook_create(
94
94
}
95
95
96
96
#[ get( "/notebooks/<notebook_id>" ) ]
97
- pub async fn notebook_get ( cluster : & Cluster , notebook_id : i64 ) -> Result < ResponseOk , Error > {
97
+ pub async fn notebook_get (
98
+ cluster : ConnectedCluster < ' _ > ,
99
+ notebook_id : i64 ,
100
+ ) -> Result < ResponseOk , Error > {
98
101
let notebook = models:: Notebook :: get_by_id ( cluster. pool ( ) , notebook_id) . await ?;
99
102
100
103
Ok ( ResponseOk ( Layout :: new ( "Notebooks" ) . render (
@@ -106,7 +109,10 @@ pub async fn notebook_get(cluster: &Cluster, notebook_id: i64) -> Result<Respons
106
109
}
107
110
108
111
#[ post( "/notebooks/<notebook_id>/reset" ) ]
109
- pub async fn notebook_reset ( cluster : & Cluster , notebook_id : i64 ) -> Result < Redirect , Error > {
112
+ pub async fn notebook_reset (
113
+ cluster : ConnectedCluster < ' _ > ,
114
+ notebook_id : i64 ,
115
+ ) -> Result < Redirect , Error > {
110
116
let notebook = models:: Notebook :: get_by_id ( cluster. pool ( ) , notebook_id) . await ?;
111
117
notebook. reset ( cluster. pool ( ) ) . await ?;
112
118
@@ -140,7 +146,7 @@ pub async fn cell_create(
140
146
141
147
#[ get( "/notebooks/<notebook_id>/cell/<cell_id>" ) ]
142
148
pub async fn cell_get (
143
- cluster : & Cluster ,
149
+ cluster : ConnectedCluster < ' _ > ,
144
150
notebook_id : i64 ,
145
151
cell_id : i64 ,
146
152
) -> Result < ResponseOk , Error > {
@@ -167,7 +173,7 @@ pub async fn cell_get(
167
173
168
174
#[ post( "/notebooks/<notebook_id>/cell/<cell_id>/edit" , data = "<data>" ) ]
169
175
pub async fn cell_edit (
170
- cluster : & Cluster ,
176
+ cluster : ConnectedCluster < ' _ > ,
171
177
notebook_id : i64 ,
172
178
cell_id : i64 ,
173
179
data : Form < forms:: Cell < ' _ > > ,
@@ -203,7 +209,7 @@ pub async fn cell_edit(
203
209
204
210
#[ get( "/notebooks/<notebook_id>/cell/<cell_id>/edit" ) ]
205
211
pub async fn cell_trigger_edit (
206
- cluster : & Cluster ,
212
+ cluster : ConnectedCluster < ' _ > ,
207
213
notebook_id : i64 ,
208
214
cell_id : i64 ,
209
215
) -> Result < ResponseOk , Error > {
@@ -229,7 +235,7 @@ pub async fn cell_trigger_edit(
229
235
230
236
#[ post( "/notebooks/<notebook_id>/cell/<cell_id>/play" ) ]
231
237
pub async fn cell_play (
232
- cluster : & Cluster ,
238
+ cluster : ConnectedCluster < ' _ > ,
233
239
notebook_id : i64 ,
234
240
cell_id : i64 ,
235
241
) -> Result < ResponseOk , Error > {
@@ -256,7 +262,7 @@ pub async fn cell_play(
256
262
257
263
#[ post( "/notebooks/<notebook_id>/cell/<cell_id>/remove" ) ]
258
264
pub async fn cell_remove (
259
- cluster : & Cluster ,
265
+ cluster : ConnectedCluster < ' _ > ,
260
266
notebook_id : i64 ,
261
267
cell_id : i64 ,
262
268
) -> Result < ResponseOk , Error > {
@@ -279,7 +285,7 @@ pub async fn cell_remove(
279
285
280
286
#[ post( "/notebooks/<notebook_id>/cell/<cell_id>/delete" ) ]
281
287
pub async fn cell_delete (
282
- cluster : & Cluster ,
288
+ cluster : ConnectedCluster < ' _ > ,
283
289
notebook_id : i64 ,
284
290
cell_id : i64 ,
285
291
) -> Result < Redirect , Error > {
@@ -295,7 +301,7 @@ pub async fn cell_delete(
295
301
}
296
302
297
303
#[ get( "/models" ) ]
298
- pub async fn models_index ( cluster : & Cluster ) -> Result < ResponseOk , Error > {
304
+ pub async fn models_index ( cluster : ConnectedCluster < ' _ > ) -> Result < ResponseOk , Error > {
299
305
let projects = models:: Project :: all ( cluster. pool ( ) ) . await ?;
300
306
let mut models = HashMap :: new ( ) ;
301
307
// let mut max_scores = HashMap::new();
@@ -328,7 +334,7 @@ pub async fn models_index(cluster: &Cluster) -> Result<ResponseOk, Error> {
328
334
}
329
335
330
336
#[ get( "/models/<id>" ) ]
331
- pub async fn models_get ( cluster : & Cluster , id : i64 ) -> Result < ResponseOk , Error > {
337
+ pub async fn models_get ( cluster : ConnectedCluster < ' _ > , id : i64 ) -> Result < ResponseOk , Error > {
332
338
let model = models:: Model :: get_by_id ( cluster. pool ( ) , id) . await ?;
333
339
let snapshot = models:: Snapshot :: get_by_id ( cluster. pool ( ) , model. snapshot_id ) . await ?;
334
340
let project = models:: Project :: get_by_id ( cluster. pool ( ) , model. project_id ) . await ?;
@@ -346,7 +352,7 @@ pub async fn models_get(cluster: &Cluster, id: i64) -> Result<ResponseOk, Error>
346
352
}
347
353
348
354
#[ get( "/snapshots" ) ]
349
- pub async fn snapshots_index ( cluster : & Cluster ) -> Result < ResponseOk , Error > {
355
+ pub async fn snapshots_index ( cluster : ConnectedCluster < ' _ > ) -> Result < ResponseOk , Error > {
350
356
let snapshots = models:: Snapshot :: all ( cluster. pool ( ) ) . await ?;
351
357
352
358
Ok ( ResponseOk (
@@ -355,7 +361,7 @@ pub async fn snapshots_index(cluster: &Cluster) -> Result<ResponseOk, Error> {
355
361
}
356
362
357
363
#[ get( "/snapshots/<id>" ) ]
358
- pub async fn snapshots_get ( cluster : & Cluster , id : i64 ) -> Result < ResponseOk , Error > {
364
+ pub async fn snapshots_get ( cluster : ConnectedCluster < ' _ > , id : i64 ) -> Result < ResponseOk , Error > {
359
365
let snapshot = models:: Snapshot :: get_by_id ( cluster. pool ( ) , id) . await ?;
360
366
let samples = snapshot. samples ( cluster. pool ( ) , 500 ) . await ?;
361
367
@@ -379,7 +385,7 @@ pub async fn snapshots_get(cluster: &Cluster, id: i64) -> Result<ResponseOk, Err
379
385
}
380
386
381
387
#[ get( "/deployments" ) ]
382
- pub async fn deployments_index ( cluster : & Cluster ) -> Result < ResponseOk , Error > {
388
+ pub async fn deployments_index ( cluster : ConnectedCluster < ' _ > ) -> Result < ResponseOk , Error > {
383
389
let projects = models:: Project :: all ( cluster. pool ( ) ) . await ?;
384
390
let mut deployments = HashMap :: new ( ) ;
385
391
@@ -401,7 +407,7 @@ pub async fn deployments_index(cluster: &Cluster) -> Result<ResponseOk, Error> {
401
407
}
402
408
403
409
#[ get( "/deployments/<id>" ) ]
404
- pub async fn deployments_get ( cluster : & Cluster , id : i64 ) -> Result < ResponseOk , Error > {
410
+ pub async fn deployments_get ( cluster : ConnectedCluster < ' _ > , id : i64 ) -> Result < ResponseOk , Error > {
405
411
let deployment = models:: Deployment :: get_by_id ( cluster. pool ( ) , id) . await ?;
406
412
let project = models:: Project :: get_by_id ( cluster. pool ( ) , deployment. project_id ) . await ?;
407
413
let model = models:: Model :: get_by_id ( cluster. pool ( ) , deployment. model_id ) . await ?;
@@ -424,7 +430,7 @@ pub async fn uploader_index() -> ResponseOk {
424
430
425
431
#[ post( "/uploader" , data = "<form>" ) ]
426
432
pub async fn uploader_upload (
427
- cluster : & Cluster ,
433
+ cluster : ConnectedCluster < ' _ > ,
428
434
form : Form < forms:: Upload < ' _ > > ,
429
435
) -> Result < Redirect , BadRequest > {
430
436
let mut uploaded_file = models:: UploadedFile :: create ( cluster. pool ( ) ) . await . unwrap ( ) ;
@@ -446,7 +452,7 @@ pub async fn uploader_upload(
446
452
}
447
453
448
454
#[ get( "/uploader/done?<table_name>" ) ]
449
- pub async fn uploaded_index ( cluster : & Cluster , table_name : & str ) -> ResponseOk {
455
+ pub async fn uploaded_index ( cluster : ConnectedCluster < ' _ > , table_name : & str ) -> ResponseOk {
450
456
let sql = templates:: Sql :: new (
451
457
cluster. pool ( ) ,
452
458
& format ! ( "SELECT * FROM {} LIMIT 10" , table_name) ,
0 commit comments