Modelle hinzugefügt

This commit is contained in:
Peter Schiwy
2024-06-03 15:41:00 +02:00
parent 6e6918e8ee
commit 534d819865
12 changed files with 122 additions and 130 deletions

View File

@@ -1,6 +1,5 @@
pub mod hersteller;
pub mod modell;
pub mod modell_temp;
pub mod typ;
use async_graphql::MergedObject;
@@ -9,6 +8,5 @@ use async_graphql::MergedObject;
pub struct Query(
typ::TypQuery,
modell::ModellQuery,
modell_temp::ModellTempQuery,
hersteller::HerstellerQuery,
);

View File

@@ -10,25 +10,16 @@ pub struct ModellQuery {
#[Object(extends)]
impl ModellQuery {
// #[graphql(external)]
// async fn id(&self) -> &i32 {
// &self.id
// }
async fn modelle<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Modell>> {
let pool = ctx.data::<PgPool>()?;
let rows = Modell::read_all(pool).await?;
Ok(rows)
}
async fn modell<'a>(&self, ctx: &'a Context<'_>, id: i32) -> FieldResult<Modell> {
let pool = ctx.data::<PgPool>()?;
let row = Modell::read_one(pool, &id).await?;
Ok(row)
}
// #[graphql(entity)]
// async fn find_modell_by_id(&self, id: i32) -> Modell {
// Modell { id }
// }
async fn modelle<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Modell>> {
let pool = ctx.data::<PgPool>()?;
let output = Modell::read_all(pool).await?;
Ok(output)
}
}

View File

@@ -1,22 +0,0 @@
use async_graphql::{Context, FieldResult, Object};
use sqlx::postgres::PgPool;
use crate::models::modell_temp::ModellTemp;
#[derive(Default)]
pub struct ModellTempQuery {}
#[Object(extends)]
impl ModellTempQuery {
// async fn modelle<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<ModellTemp>> {
// let pool = ctx.data::<PgPool>()?;
// let rows = ModellTemp::read_all(pool).await?;
// Ok(rows)
// }
async fn modell_temp<'a>(&self, ctx: &'a Context<'_>, id: i32) -> FieldResult<ModellTemp> {
let pool = ctx.data::<PgPool>()?;
let row = ModellTemp::read_one(pool, &id).await?;
Ok(row)
}
}