Skip to content

Commit fc90898

Browse files
committed
sentry - middleware - channel_load - ChannelParam
1 parent fb5e363 commit fc90898

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

sentry/src/middleware/channel.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
use std::sync::Arc;
22

3-
use crate::{
4-
db::get_channel_by_id, middleware::Middleware, response::ResponseError,
5-
routes::routers::RouteParams, Application, Auth,
6-
};
73
use adapter::client::Locked;
84
use axum::{
95
extract::{Path, RequestParts},
@@ -15,6 +11,12 @@ use hyper::{Body, Request};
1511
use primitives::ChannelId;
1612

1713
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+
};
1820

1921
#[derive(Debug)]
2022
pub struct ChannelLoad;
@@ -70,6 +72,13 @@ fn channel_load_old<C: Locked>(
7072
.boxed()
7173
}
7274

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+
7382
pub async fn channel_load<C: Locked + 'static, B>(
7483
request: axum::http::Request<B>,
7584
next: Next<B>,
@@ -86,12 +95,12 @@ where
8695
// running extractors requires a `RequestParts`
8796
let mut request_parts = RequestParts::new(request);
8897

89-
let channel_id = request_parts
90-
.extract::<Path<ChannelId>>()
98+
let channel_param = request_parts
99+
.extract::<Path<ChannelParam>>()
91100
.await
92101
.map_err(|_| ResponseError::BadRequest("Bad Channel Id".to_string()))?;
93102

94-
let channel = get_channel_by_id(&app.pool, &channel_id)
103+
let channel = get_channel_by_id(&app.pool, &channel_param.id)
95104
.await?
96105
.ok_or(ResponseError::NotFound)?;
97106

0 commit comments

Comments
 (0)