From b9cfbbb420a66296c42fd863fe0bd0fa6f7445c1 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 30 Aug 2024 19:26:19 +0200 Subject: Add filter for alert by id --- src/graphql/types/alert.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'src/graphql/types') 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, + // Optional limit results limit: Option, @@ -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 = rows .iter() -- cgit v1.2.3-71-g8e6c