refactor queries

This commit is contained in:
2026-05-31 22:03:06 +02:00
parent 90a88c15dc
commit 7ffd06f446
13 changed files with 15 additions and 7 deletions

View File

@@ -1,5 +1,6 @@
pub mod dataloader;
pub mod entity;
pub mod model;
pub mod queries;
pub mod repository;
pub mod service;

View File

@@ -0,0 +1 @@
pub mod benutzer;

View 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)
}
}

View File

@@ -1,5 +1,6 @@
pub mod dataloader;
pub mod entity;
pub mod model;
pub mod queries;
pub mod repository;
pub mod service;

View File

@@ -0,0 +1 @@
pub mod gruppe;

View 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)
}
}

View File

@@ -1,5 +1,6 @@
pub mod dataloader;
pub mod entity;
pub mod model;
pub mod queries;
pub mod repository;
pub mod service;

View File

@@ -0,0 +1 @@
pub mod rolle;

View 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)
}
}

View File

@@ -1,5 +1,6 @@
pub mod dataloader;
pub mod entity;
pub mod model;
pub mod queries;
pub mod repository;
pub mod service;

View File

@@ -0,0 +1 @@
pub mod typ;

View 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)
}
}