From 7b9e9d2da5d85f23d43724fe2ca5012918ea54be Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Fri, 23 Aug 2024 22:19:32 +0200 Subject: Add doc --- src/graphql/types/position.rs | 10 ++++++++++ src/graphql/types/user.rs | 6 ++++++ 2 files changed, 16 insertions(+) (limited to 'src/graphql/types') diff --git a/src/graphql/types/position.rs b/src/graphql/types/position.rs index 8b2d658..86e219c 100644 --- a/src/graphql/types/position.rs +++ b/src/graphql/types/position.rs @@ -8,6 +8,7 @@ use tokio_postgres::types::{to_sql_checked, FromSql, IsNull, ToSql, Type}; use super::user::find_user; #[derive(Enum, Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] +/// Enumeration which refers to the kind of moving activity pub enum MovingActivity { // "Car" of the doc InVehicle, @@ -67,6 +68,7 @@ impl ToSql for MovingActivity { } #[derive(Clone, Debug, Serialize, Deserialize)] +/// Position struct pub struct Position { pub id: i32, pub user_id: i32, @@ -103,10 +105,18 @@ impl Position { } } +/// Get positions from the database pub async fn get_positions<'ctx>( ctx: &Context<'ctx>, + + // Optional filter by user id. If not defined returns only available positions: + // If claimed user is admin returns everything, otherwise only positions linked to that user. user_id: Option, + + // Optional limit results limit: Option, + + // Optional offset results. It should be used with limit field. offset: Option, ) -> Result>, String> { let state = ctx.data::().expect("Can't connect to db"); diff --git a/src/graphql/types/user.rs b/src/graphql/types/user.rs index 4ecf086..96fcf40 100644 --- a/src/graphql/types/user.rs +++ b/src/graphql/types/user.rs @@ -6,6 +6,7 @@ use tokio_postgres::Client; use super::jwt::Authentication; #[derive(Clone, Debug, Serialize, Deserialize)] +/// User struct pub struct User { pub id: i32, pub email: String, @@ -32,9 +33,13 @@ impl User { } } +/// Get users from the database pub async fn get_users<'ctx>( ctx: &Context<'ctx>, + + // Optional limit results limit: Option, + // Optional offset results. It should be used with limit field. offset: Option, ) -> Result>, String> { let state = ctx.data::().expect("Can't connect to db"); @@ -66,6 +71,7 @@ pub async fn get_users<'ctx>( } } +/// Find an user with id = `id` using the PostgreSQL `client` pub async fn find_user(client: &Client, id: i32) -> Result { let rows = client .query( -- cgit v1.2.3-71-g8e6c