Skip to content
This repository has been archived by the owner on Jul 23, 2024. It is now read-only.

Commit

Permalink
Graphql query and mutation for crystal library
Browse files Browse the repository at this point in the history
  • Loading branch information
iamvigneshwars committed Feb 20, 2024
1 parent fe530b7 commit 1b0da8d
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 55 deletions.
79 changes: 40 additions & 39 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/crystal_library/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ edition = "2021"
async-graphql = { workspace = true }
axum = { workspace = true }
clap = { workspace = true }
chrono ={ workspace = true }
dotenvy = { workspace = true }
graphql_endpoints = { path = "../graphql_endpoints" }
opa_client = { path = "../opa_client", features = ["graphql"] }
Expand Down
7 changes: 4 additions & 3 deletions backend/crystal_library/src/entities/crystal_wells.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
//src/entities/compound_instances.rs

use async_graphql::SimpleObject;
use chrono::{DateTime, Utc};
use sea_orm::{
ActiveModelBehavior, DeriveEntityModel, DerivePrimaryKey, DeriveRelation, EntityTrait,
EnumIter, PrimaryKeyTrait,
Expand All @@ -14,7 +13,9 @@ pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub plate_id: Uuid,
pub well_num: i16,
pub well_number: i16,
pub operator_id: String,
pub timestamp: DateTime<Utc>,
}

#[derive(Clone, Copy, Debug, EnumIter, DeriveRelation)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// src/resolvers/crystal_wells_res.rs

use crate::entities::crystal_wells;
use async_graphql::{Context, Object};
use chrono::Utc;
use opa_client::subject_authorization;
use sea_orm::{ActiveValue, DatabaseConnection, EntityTrait};
use the_paginator::graphql::{CursorInput, ModelConnection};
Expand Down Expand Up @@ -46,14 +45,17 @@ impl CrystalMutation {
&self,
ctx: &Context<'_>,
plate_id: Uuid,
well_num: i16,
well_number: i16,
) -> async_graphql::Result<crystal_wells::Model> {
subject_authorization!("xchemlab.crystal_library.write_crystal", ctx).await?;
let operator_id =
subject_authorization!("xchemlab.crystal_library.write_crystal", ctx).await?;
let db = ctx.data::<DatabaseConnection>()?;
let crystal = crystal_wells::ActiveModel {
id: ActiveValue::Set(Uuid::now_v7()),
plate_id: ActiveValue::Set(plate_id),
well_num: ActiveValue::Set(well_num),
well_number: ActiveValue::Set(well_number),
operator_id: ActiveValue::Set(operator_id),
timestamp: ActiveValue::Set(Utc::now()),
};
Ok(crystal_wells::Entity::insert(crystal)
.exec_with_returning(db)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/graphql.rs
pub mod crystal_wells_res;

use crate::resolvers::crystal_wells_res::{CrystalMutation, CrystalQuery};
use async_graphql::{EmptySubscription, MergedObject, Schema, SchemaBuilder};
use crystal_wells_res::{CrystalMutation, CrystalQuery};

#[derive(Debug, Clone, MergedObject, Default)]
pub struct Query(CrystalQuery);
Expand Down
3 changes: 0 additions & 3 deletions backend/crystal_library/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
// main.rs

mod entities;
mod graphql;
mod migrator;
mod resolvers;

use async_graphql::extensions::Tracing;
use axum::{routing::get, Router, Server};
Expand Down
2 changes: 0 additions & 2 deletions backend/crystal_library/src/migrator.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// src/migrator.rs

use crate::entities::crystal_wells;
use axum::async_trait;
use sea_orm::{DbErr, DeriveMigrationName, Schema};
Expand Down
1 change: 0 additions & 1 deletion backend/crystal_library/src/resolvers/mod.rs

This file was deleted.

0 comments on commit 1b0da8d

Please sign in to comment.