1
1
use std:: sync:: Arc ;
2
2
3
- use crate :: {
4
- db:: get_channel_by_id, middleware:: Middleware , response:: ResponseError ,
5
- routes:: routers:: RouteParams , Application , Auth ,
6
- } ;
7
3
use adapter:: client:: Locked ;
8
4
use axum:: {
9
5
extract:: { Path , RequestParts } ,
@@ -15,6 +11,12 @@ use hyper::{Body, Request};
15
11
use primitives:: ChannelId ;
16
12
17
13
use async_trait:: async_trait;
14
+ use serde:: Deserialize ;
15
+
16
+ use crate :: {
17
+ db:: get_channel_by_id, middleware:: Middleware , response:: ResponseError ,
18
+ routes:: routers:: RouteParams , Application , Auth ,
19
+ } ;
18
20
19
21
#[ derive( Debug ) ]
20
22
pub struct ChannelLoad ;
@@ -70,6 +72,13 @@ fn channel_load_old<C: Locked>(
70
72
. boxed ( )
71
73
}
72
74
75
+ /// This struct is required because of routes that have more parameters
76
+ /// apart from the `ChannelId`
77
+ #[ derive( Debug , Deserialize ) ]
78
+ struct ChannelParam {
79
+ pub id : ChannelId ,
80
+ }
81
+
73
82
pub async fn channel_load < C : Locked + ' static , B > (
74
83
request : axum:: http:: Request < B > ,
75
84
next : Next < B > ,
@@ -86,12 +95,12 @@ where
86
95
// running extractors requires a `RequestParts`
87
96
let mut request_parts = RequestParts :: new ( request) ;
88
97
89
- let channel_id = request_parts
90
- . extract :: < Path < ChannelId > > ( )
98
+ let channel_param = request_parts
99
+ . extract :: < Path < ChannelParam > > ( )
91
100
. await
92
101
. map_err ( |_| ResponseError :: BadRequest ( "Bad Channel Id" . to_string ( ) ) ) ?;
93
102
94
- let channel = get_channel_by_id ( & app. pool , & channel_id )
103
+ let channel = get_channel_by_id ( & app. pool , & channel_param . id )
95
104
. await ?
96
105
. ok_or ( ResponseError :: NotFound ) ?;
97
106
0 commit comments