-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
bccb131
commit 53300de
Showing
4 changed files
with
72 additions
and
24 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
use async_graphql::SimpleObject; | ||
use models::data_collection_file_attachment; | ||
|
||
#[derive(Clone, Debug, PartialEq, SimpleObject)] | ||
#[graphql(name = "DataProcessing")] | ||
pub struct DataProcessing { | ||
/// An opaque unique identifier for the collected file attachment | ||
pub data_collection_file_attachment_id: u32, | ||
/// Full path where the processed image is stored | ||
pub file_full_path: String, | ||
} | ||
|
||
impl From<data_collection_file_attachment::Model> for DataProcessing { | ||
fn from(values: data_collection_file_attachment::Model) -> Self { | ||
Self { | ||
data_collection_file_attachment_id: values.data_collection_file_attachment_id, | ||
file_full_path: values.file_full_path, | ||
} | ||
} | ||
} | ||
|
||
#[derive(SimpleObject)] | ||
#[graphql(name = "Datasets", complex)] | ||
pub struct DataCollection { | ||
/// An opaque unique identifier for the data collection | ||
pub data_collection_id: u32, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/// Collection of graphql entities | ||
mod entities; | ||
|
||
use async_graphql::{ | ||
Context, ComplexObject, EmptyMutation, EmptySubscription, Object, Schema, SchemaBuilder, | ||
}; | ||
use entities::{DataProcessing, DataCollection}; | ||
use sea_orm::{DatabaseConnection, EntityTrait, QueryFilter, ColumnTrait}; | ||
use models::data_collection_file_attachment; | ||
|
||
/// The GraphQL schema exposed by the service | ||
pub type RootSchema = Schema<Query, EmptyMutation, EmptySubscription>; | ||
|
||
/// A schema builder for the service | ||
pub fn root_schema_builder() -> SchemaBuilder<Query, EmptyMutation, EmptySubscription> { | ||
Schema::build(Query, EmptyMutation, EmptySubscription).enable_federation() | ||
} | ||
|
||
/// The root query of the service | ||
#[derive(Debug, Clone, Default)] | ||
pub struct Query; | ||
|
||
#[ComplexObject] | ||
impl DataCollection { | ||
/// Fetched all the processed data from data collection during a session | ||
async fn processed_data(&self, ctx: &Context<'_>) -> Result<Vec<DataProcessing>, async_graphql::Error> { | ||
let database = ctx.data::<DatabaseConnection>()?; | ||
Ok(data_collection_file_attachment::Entity::find() | ||
.filter(data_collection_file_attachment::Column::DataCollectionId.eq(self.data_collection_id)) | ||
.all(database) | ||
.await? | ||
.into_iter() | ||
.map(DataProcessing::from) | ||
.collect()) | ||
} | ||
} | ||
|
||
#[Object] | ||
impl Query { | ||
/// Reference datasets resolver for the router | ||
#[graphql(entity)] | ||
async fn router_data_collection(&self, data_collection_id: u32) -> DataCollection { | ||
DataCollection { data_collection_id } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters