refactor queries
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
pub mod dataloader;
|
||||
pub mod entity;
|
||||
pub mod model;
|
||||
pub mod queries;
|
||||
pub mod repository;
|
||||
pub mod service;
|
||||
|
||||
1
src/domain/benutzer/queries.rs
Normal file
1
src/domain/benutzer/queries.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod benutzer;
|
||||
24
src/domain/benutzer/queries/benutzer.rs
Normal file
24
src/domain/benutzer/queries/benutzer.rs
Normal file
@@ -0,0 +1,24 @@
|
||||
use async_graphql::{Context, FieldResult, Object};
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
use crate::domain::benutzer::{model::Benutzer, service::Service};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct BenutzerQuery {}
|
||||
|
||||
#[Object(extends)]
|
||||
impl BenutzerQuery {
|
||||
// async fn rolle<'a>(&self, ctx: &'a Context<'_>, id: Id) -> FieldResult<Modell> {
|
||||
// let pool = ctx.data::<PgPool>()?;
|
||||
// let row = Modell::read_one(pool, &id).await?;
|
||||
// Ok(row)
|
||||
// }
|
||||
|
||||
async fn benutzer_alle(&self, ctx: &Context<'_>) -> FieldResult<Vec<Benutzer>> {
|
||||
let pool = ctx.data::<PgPool>()?;
|
||||
|
||||
let benutzer = Service::new(pool.clone()).alle_benutzer().await?;
|
||||
|
||||
Ok(benutzer)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod dataloader;
|
||||
pub mod entity;
|
||||
pub mod model;
|
||||
pub mod queries;
|
||||
pub mod repository;
|
||||
pub mod service;
|
||||
|
||||
1
src/domain/gruppe/queries.rs
Normal file
1
src/domain/gruppe/queries.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod gruppe;
|
||||
23
src/domain/gruppe/queries/gruppe.rs
Normal file
23
src/domain/gruppe/queries/gruppe.rs
Normal file
@@ -0,0 +1,23 @@
|
||||
use async_graphql::{Context, FieldResult, Object};
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
use crate::domain::gruppe::{model::Gruppe, service::Service};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct GruppeQuery {}
|
||||
|
||||
#[Object(extends)]
|
||||
impl GruppeQuery {
|
||||
// async fn gruppe(&self, ctx: &Context<'_>, id: uuid::Uuid) -> FieldResult<Gruppe> {
|
||||
// todo!();
|
||||
// // let pool = ctx.data::<PgPool>()?;
|
||||
// //
|
||||
// // Ok(row)
|
||||
// }
|
||||
|
||||
async fn gruppen(&self, ctx: &Context<'_>) -> FieldResult<Vec<Gruppe>> {
|
||||
let pool = ctx.data::<PgPool>()?;
|
||||
let rows = Service::new(pool.clone()).gruppe_alle().await?;
|
||||
Ok(rows)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod dataloader;
|
||||
pub mod entity;
|
||||
pub mod model;
|
||||
pub mod queries;
|
||||
pub mod repository;
|
||||
pub mod service;
|
||||
|
||||
1
src/domain/rolle/queries.rs
Normal file
1
src/domain/rolle/queries.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod rolle;
|
||||
26
src/domain/rolle/queries/rolle.rs
Normal file
26
src/domain/rolle/queries/rolle.rs
Normal file
@@ -0,0 +1,26 @@
|
||||
use async_graphql::{Context, FieldResult, Object};
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
use crate::domain::rolle::model::Rolle;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct RolleQuery {}
|
||||
|
||||
#[Object(extends)]
|
||||
impl RolleQuery {
|
||||
// async fn rolle<'a>(&self, ctx: &'a Context<'_>, id: Id) -> FieldResult<Modell> {
|
||||
// let pool = ctx.data::<PgPool>()?;
|
||||
// let row = Modell::read_one(pool, &id).await?;
|
||||
// Ok(row)
|
||||
// }
|
||||
|
||||
async fn rollen(&self, ctx: &Context<'_>) -> FieldResult<Vec<Rolle>> {
|
||||
let pool = ctx.data::<PgPool>()?;
|
||||
|
||||
let rollen = sqlx::query_as!(Rolle, "SELECT * FROM rollen")
|
||||
.fetch_all(pool)
|
||||
.await?;
|
||||
|
||||
Ok(rollen)
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
pub mod dataloader;
|
||||
pub mod entity;
|
||||
pub mod model;
|
||||
pub mod queries;
|
||||
pub mod repository;
|
||||
pub mod service;
|
||||
|
||||
1
src/domain/typ/queries.rs
Normal file
1
src/domain/typ/queries.rs
Normal file
@@ -0,0 +1 @@
|
||||
pub mod typ;
|
||||
16
src/domain/typ/queries/typ.rs
Normal file
16
src/domain/typ/queries/typ.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
use async_graphql::{Context, FieldResult, Object};
|
||||
use sqlx::postgres::PgPool;
|
||||
|
||||
use crate::domain::typ::{model::Typ, service::Service};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct TypQuery {}
|
||||
|
||||
#[Object(extends)]
|
||||
impl TypQuery {
|
||||
async fn typen(&self, ctx: &Context<'_>) -> FieldResult<Vec<Typ>> {
|
||||
let pool = ctx.data::<PgPool>()?;
|
||||
let typen = Service::new(pool.clone()).typ_alle().await?;
|
||||
Ok(typen)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user