diff --git a/datasets/src/graphql/entity.rs b/datasets/src/graphql/entity.rs index a1b19ab..a71bebe 100644 --- a/datasets/src/graphql/entity.rs +++ b/datasets/src/graphql/entity.rs @@ -4,12 +4,10 @@ use chrono::{DateTime, Utc}; use models::data_collection; #[derive(Clone, Debug, PartialEq, SimpleObject)] -#[graphql(name = "datasets")] +#[graphql(name = "Datasets")] pub struct DataCollection { /// An opaque unique identifier for the data collection pub data_collection_id: u32, - /// An opaque unique identifier for the session - pub sessionid: Option, /// The date time and which data collection began pub start_time: Option>, /// The date time and which data collection ended @@ -36,25 +34,24 @@ pub struct DataCollection { pub data_collection_group_id: i32, /// An opaque unique identifier for the detector pub detector_id: Option, - /// Location of the image stored - pub image_directory: Option, + /// Location of the image stored + pub image_directory: Option, /// Image file name without extension pub image_suffix: Option, /// Image file extension - pub image_prefix: Option, + pub image_prefix: Option, } #[derive(SimpleObject)] -#[graphql(name = "sessions", complex)] +#[graphql(name = "Session", complex)] pub struct Session { - pub session_id: i32, + pub id: i32, } impl From for DataCollection { fn from(values: data_collection::Model) -> Self { Self { data_collection_id: values.data_collection_id, - sessionid: values.sessionid, start_time: values.start_time.map(|time| time.and_utc()), end_time: values.end_time.map(|time| time.and_utc()), number_of_images: values.number_of_images, @@ -69,7 +66,7 @@ impl From for DataCollection { data_collection_group_id: values.data_collection_group_id, detector_id: values.detector_id, image_directory: values.image_directory, - image_suffix: values.image_suffix, + image_suffix: values.image_suffix, image_prefix: values.image_prefix, } } diff --git a/datasets/src/graphql/mod.rs b/datasets/src/graphql/mod.rs index b0d8349..57d20e8 100644 --- a/datasets/src/graphql/mod.rs +++ b/datasets/src/graphql/mod.rs @@ -1,42 +1,40 @@ mod entity; -use async_graphql::{ComplexObject, Context, EmptyMutation, EmptySubscription, Object, Schema, SchemaBuilder}; +use async_graphql::{ + ComplexObject, Context, EmptyMutation, EmptySubscription, Object, Schema, SchemaBuilder, +}; use entity::{DataCollection, Session}; use models::data_collection; -use sea_orm::{DatabaseConnection, EntityTrait, QueryFilter, ColumnTrait}; +use sea_orm::{ColumnTrait, DatabaseConnection, EntityTrait, QueryFilter}; /// The GraphQL schema exposed by the service -pub type RootSchema = Schema; +pub type RootSchema = Schema; /// A schema builder for the service -pub fn root_schema_builder() -> SchemaBuilder { - Schema::build(RootQuery, EmptyMutation, EmptySubscription).enable_federation() +pub fn root_schema_builder() -> SchemaBuilder { + Schema::build(Query, EmptyMutation, EmptySubscription).enable_federation() } /// The root query of the service #[derive(Debug, Clone, Default)] -pub struct RootQuery; +pub struct Query; #[ComplexObject] -impl Session{ - async fn datasets( - &self, - ctx: &Context<'_>, - ) -> async_graphql::Result> { +impl Session { + async fn datasets(&self, ctx: &Context<'_>) -> async_graphql::Result> { let database = ctx.data::()?; Ok(data_collection::Entity::find() - .filter(data_collection::Column::Sessionid.eq(self.session_id)) + .filter(data_collection::Column::Sessionid.eq(self.id)) .all(database) .await? .into_iter() .map(DataCollection::from) - .collect() - ) + .collect()) } } #[Object] -impl RootQuery { +impl Query { /// Retrieves all datasets collected during Sessions async fn datasets( &self, @@ -73,13 +71,7 @@ impl RootQuery { } #[graphql(entity)] - async fn router_sessions( - &self, - session_id: i32 - ) -> Session { - Session { - session_id, - } + async fn router_sessions(&self, id: i32) -> Session { + Session { id } } - }