refactoring

This commit is contained in:
Peter Schiwy
2024-06-07 14:40:44 +02:00
parent bb1946bb83
commit 1d60fc5a3f
5 changed files with 28 additions and 37 deletions

View File

@@ -4,21 +4,19 @@ use sqlx::postgres::PgPool;
use crate::models::hersteller::Hersteller;
#[derive(Default)]
pub struct HerstellerQuery {
pub id: i32,
}
pub struct HerstellerQuery {}
#[Object(extends)]
impl HerstellerQuery {
async fn alle_hersteller<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Hersteller>> {
let pool = ctx.data::<PgPool>()?;
let rows = Hersteller::read_all(pool).await?;
Ok(rows)
}
async fn hersteller<'a>(&self, ctx: &'a Context<'_>, id: i32) -> FieldResult<Hersteller> {
let pool = ctx.data::<PgPool>()?;
let row = Hersteller::read_one(pool, &id).await?;
Ok(row)
}
async fn alle_hersteller<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Hersteller>> {
let pool = ctx.data::<PgPool>()?;
let rows = Hersteller::read_all(pool).await?;
Ok(rows)
}
}