1
1
use crate :: http_server:: routes:: middlewares;
2
- use crate :: DependencyContainer ;
2
+ use crate :: http_server :: routes :: router :: RouterState ;
3
3
use warp:: Filter ;
4
4
5
5
pub fn routes (
6
- dependency_manager : & DependencyContainer ,
6
+ router_state : & RouterState ,
7
7
) -> impl Filter < Extract = ( impl warp:: Reply , ) , Error = warp:: Rejection > + Clone {
8
- artifact_cardano_stake_distributions ( dependency_manager)
9
- . or ( artifact_cardano_stake_distribution_by_id (
10
- dependency_manager,
11
- ) )
12
- . or ( artifact_cardano_stake_distribution_by_epoch (
13
- dependency_manager,
14
- ) )
8
+ artifact_cardano_stake_distributions ( router_state)
9
+ . or ( artifact_cardano_stake_distribution_by_id ( router_state) )
10
+ . or ( artifact_cardano_stake_distribution_by_epoch ( router_state) )
15
11
}
16
12
17
13
/// GET /artifact/cardano-stake-distributions
18
14
fn artifact_cardano_stake_distributions (
19
- dependency_manager : & DependencyContainer ,
15
+ router_state : & RouterState ,
20
16
) -> impl Filter < Extract = ( impl warp:: Reply , ) , Error = warp:: Rejection > + Clone {
21
17
warp:: path!( "artifact" / "cardano-stake-distributions" )
22
18
. and ( warp:: get ( ) )
23
- . and ( middlewares:: with_logger ( dependency_manager ) )
24
- . and ( middlewares:: with_http_message_service ( dependency_manager ) )
19
+ . and ( middlewares:: with_logger ( router_state ) )
20
+ . and ( middlewares:: with_http_message_service ( router_state ) )
25
21
. and_then ( handlers:: list_artifacts)
26
22
}
27
23
28
24
/// GET /artifact/cardano-stake-distribution/:id
29
25
fn artifact_cardano_stake_distribution_by_id (
30
- dependency_manager : & DependencyContainer ,
26
+ router_state : & RouterState ,
31
27
) -> impl Filter < Extract = ( impl warp:: Reply , ) , Error = warp:: Rejection > + Clone {
32
28
warp:: path!( "artifact" / "cardano-stake-distribution" / String )
33
29
. and ( warp:: get ( ) )
34
- . and ( middlewares:: with_logger ( dependency_manager ) )
35
- . and ( middlewares:: with_http_message_service ( dependency_manager ) )
36
- . and ( middlewares:: with_metrics_service ( dependency_manager ) )
30
+ . and ( middlewares:: with_logger ( router_state ) )
31
+ . and ( middlewares:: with_http_message_service ( router_state ) )
32
+ . and ( middlewares:: with_metrics_service ( router_state ) )
37
33
. and_then ( handlers:: get_artifact_by_signed_entity_id)
38
34
}
39
35
40
36
/// GET /artifact/cardano-stake-distribution/epoch/:epoch
41
37
fn artifact_cardano_stake_distribution_by_epoch (
42
- dependency_manager : & DependencyContainer ,
38
+ router_state : & RouterState ,
43
39
) -> impl Filter < Extract = ( impl warp:: Reply , ) , Error = warp:: Rejection > + Clone {
44
40
warp:: path!( "artifact" / "cardano-stake-distribution" / "epoch" / String )
45
41
. and ( warp:: get ( ) )
46
- . and ( middlewares:: with_logger ( dependency_manager ) )
47
- . and ( middlewares:: with_http_message_service ( dependency_manager ) )
48
- . and ( middlewares:: with_metrics_service ( dependency_manager ) )
42
+ . and ( middlewares:: with_logger ( router_state ) )
43
+ . and ( middlewares:: with_http_message_service ( router_state ) )
44
+ . and ( middlewares:: with_metrics_service ( router_state ) )
49
45
. and_then ( handlers:: get_artifact_by_epoch)
50
46
}
51
47
@@ -170,7 +166,7 @@ pub mod tests {
170
166
use super :: * ;
171
167
172
168
fn setup_router (
173
- dependency_manager : Arc < DependencyContainer > ,
169
+ state : RouterState ,
174
170
) -> impl Filter < Extract = ( impl warp:: Reply , ) , Error = warp:: Rejection > + Clone {
175
171
let cors = warp:: cors ( )
176
172
. allow_any_origin ( )
@@ -179,7 +175,7 @@ pub mod tests {
179
175
180
176
warp:: any ( )
181
177
. and ( warp:: path ( SERVER_BASE_PATH ) )
182
- . and ( routes ( & dependency_manager ) . with ( cors) )
178
+ . and ( routes ( & state ) . with ( cors) )
183
179
}
184
180
185
181
#[ tokio:: test]
@@ -199,7 +195,9 @@ pub mod tests {
199
195
let response = request ( )
200
196
. method ( method)
201
197
. path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
202
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
198
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
199
+ dependency_manager,
200
+ ) ) ) )
203
201
. await ;
204
202
205
203
APISpec :: verify_conformity (
@@ -230,7 +228,9 @@ pub mod tests {
230
228
let response = request ( )
231
229
. method ( method)
232
230
. path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
233
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
231
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
232
+ dependency_manager,
233
+ ) ) ) )
234
234
. await ;
235
235
236
236
APISpec :: verify_conformity (
@@ -260,7 +260,9 @@ pub mod tests {
260
260
request ( )
261
261
. method ( method)
262
262
. path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
263
- . reply ( & setup_router ( dependency_manager. clone ( ) ) )
263
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config (
264
+ dependency_manager. clone ( ) ,
265
+ ) ) )
264
266
. await ;
265
267
266
268
assert_eq ! (
@@ -278,7 +280,9 @@ pub mod tests {
278
280
request ( )
279
281
. method ( method)
280
282
. path ( & format ! ( "/{SERVER_BASE_PATH}{base_path}/123" ) )
281
- . reply ( & setup_router ( dependency_manager. clone ( ) ) )
283
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config (
284
+ dependency_manager. clone ( ) ,
285
+ ) ) )
282
286
. await ;
283
287
284
288
assert_eq ! (
@@ -308,7 +312,9 @@ pub mod tests {
308
312
let response = request ( )
309
313
. method ( method)
310
314
. path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
311
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
315
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
316
+ dependency_manager,
317
+ ) ) ) )
312
318
. await ;
313
319
314
320
APISpec :: verify_conformity (
@@ -339,7 +345,9 @@ pub mod tests {
339
345
let response = request ( )
340
346
. method ( method)
341
347
. path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
342
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
348
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
349
+ dependency_manager,
350
+ ) ) ) )
343
351
. await ;
344
352
345
353
APISpec :: verify_conformity (
@@ -370,7 +378,9 @@ pub mod tests {
370
378
let response = request ( )
371
379
. method ( method)
372
380
. path ( & format ! ( "/{SERVER_BASE_PATH}{path}" ) )
373
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
381
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
382
+ dependency_manager,
383
+ ) ) ) )
374
384
. await ;
375
385
376
386
APISpec :: verify_conformity (
@@ -402,7 +412,9 @@ pub mod tests {
402
412
let response = request ( )
403
413
. method ( method)
404
414
. path ( & format ! ( "/{SERVER_BASE_PATH}{base_path}/123" ) )
405
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
415
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
416
+ dependency_manager,
417
+ ) ) ) )
406
418
. await ;
407
419
408
420
APISpec :: verify_conformity (
@@ -429,7 +441,9 @@ pub mod tests {
429
441
let response = request ( )
430
442
. method ( method)
431
443
. path ( & format ! ( "/{SERVER_BASE_PATH}{base_path}/invalid-epoch" ) )
432
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
444
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
445
+ dependency_manager,
446
+ ) ) ) )
433
447
. await ;
434
448
435
449
APISpec :: verify_conformity (
@@ -460,7 +474,9 @@ pub mod tests {
460
474
let response = request ( )
461
475
. method ( method)
462
476
. path ( & format ! ( "/{SERVER_BASE_PATH}{base_path}/123" ) )
463
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
477
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
478
+ dependency_manager,
479
+ ) ) ) )
464
480
. await ;
465
481
466
482
APISpec :: verify_conformity (
@@ -491,7 +507,9 @@ pub mod tests {
491
507
let response = request ( )
492
508
. method ( method)
493
509
. path ( & format ! ( "/{SERVER_BASE_PATH}{base_path}/123" ) )
494
- . reply ( & setup_router ( Arc :: new ( dependency_manager) ) )
510
+ . reply ( & setup_router ( RouterState :: new_with_dummy_config ( Arc :: new (
511
+ dependency_manager,
512
+ ) ) ) )
495
513
. await ;
496
514
497
515
APISpec :: verify_conformity (
0 commit comments