Skip to content

Commit d9db398

Browse files
committed
sentry - routes - event_aggregate - finish up implementation
1 parent 96d3d8c commit d9db398

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

sentry/src/routes/event_aggregate.rs

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
1-
use crate::{Application, ResponseError, Session};
1+
use chrono::{serde::ts_milliseconds_option, DateTime, Utc};
22
use hyper::{Body, Request, Response};
3-
use primitives::adapter::Adapter;
4-
use primitives::Channel;
3+
use serde::Deserialize;
4+
5+
use primitives::{adapter::Adapter, sentry::EventAggregateResponse, Channel};
6+
7+
use crate::{db::list_event_aggregates, success_response, Application, ResponseError, Session};
8+
9+
#[derive(Deserialize)]
10+
pub struct EventAggregatesQuery {
11+
#[serde(default, with = "ts_milliseconds_option")]
12+
after: Option<DateTime<Utc>>,
13+
}
514

615
pub async fn list_channel_event_aggregates<A: Adapter>(
716
req: Request<Body>,
8-
_app: &Application<A>,
17+
app: &Application<A>,
918
) -> Result<Response<Body>, ResponseError> {
1019
let channel = req
1120
.extensions()
1221
.get::<Channel>()
1322
.expect("Request should have Channel");
1423

15-
// TODO: Auth required middleware
1624
let session = req
1725
.extensions()
1826
.get::<Session>()
1927
.ok_or_else(|| ResponseError::Unauthorized)?;
2028

21-
let _is_superuser = channel.spec.validators.find(&session.uid).is_some();
29+
let query =
30+
serde_urlencoded::from_str::<EventAggregatesQuery>(req.uri().query().unwrap_or(""))?;
31+
32+
let from = if channel.spec.validators.find(&session.uid).is_some() {
33+
Some(session.uid.clone())
34+
} else {
35+
None
36+
};
37+
38+
let event_aggregates =
39+
list_event_aggregates(&app.pool, app.config.events_find_limit, &from, &query.after).await?;
40+
41+
let response = EventAggregateResponse {
42+
channel: channel.clone(),
43+
events: event_aggregates,
44+
};
2245

23-
unimplemented!("Still need to finish it")
46+
Ok(success_response(serde_json::to_string(&response)?))
2447
}

0 commit comments

Comments
 (0)