diff options
| author | Santo Cariotti <santo@dcariotti.me> | 2024-08-30 17:26:19 +0000 |
|---|---|---|
| committer | Santo Cariotti <santo@dcariotti.me> | 2024-08-30 17:26:19 +0000 |
| commit | b9cfbbb420a66296c42fd863fe0bd0fa6f7445c1 (patch) | |
| tree | 25de6f3707593a342bcdbc926002703c02f665c3 /src/graphql/types | |
| parent | e118a43c9ba1719be403d6e7a0f8c610319c144c (diff) | |
Add filter for alert by id
Diffstat (limited to 'src/graphql/types')
| -rw-r--r-- | src/graphql/types/alert.rs | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/graphql/types/alert.rs b/src/graphql/types/alert.rs index 9c21013..970864f 100644 --- a/src/graphql/types/alert.rs +++ b/src/graphql/types/alert.rs @@ -87,6 +87,9 @@ pub struct AlertInput { pub async fn get_alerts<'ctx>( ctx: &Context<'ctx>, + // Optional filter by id. + id: Option<i32>, + // Optional limit results limit: Option<i64>, @@ -99,8 +102,17 @@ pub async fn get_alerts<'ctx>( match auth { Authentication::NotLogged => Err("Unauthorized".to_string()), Authentication::Logged(_) => { - let rows = client - .query( + let rows= + match id { + Some(id) => client.query( + "SELECT id, user_id, extract(epoch from created_at)::double precision as created_at, ST_AsText(area) as area, level, reached_users + FROM alerts + WHERE id = $1", + &[&id], + ) + .await + .unwrap(), + None => client.query( "SELECT id, user_id, extract(epoch from created_at)::double precision as created_at, ST_AsText(area) as area, level, reached_users FROM alerts ORDER BY id DESC @@ -109,7 +121,9 @@ pub async fn get_alerts<'ctx>( &[&limit.unwrap_or(20), &offset.unwrap_or(0)], ) .await - .unwrap(); + .unwrap() + + }; let positions: Vec<Alert> = rows .iter() |
