First Commit

This commit is contained in:
Peter Schiwy
2024-05-31 00:32:51 +02:00
commit bab592edf1
23 changed files with 3268 additions and 0 deletions

35
src/queries/hersteller.rs Normal file
View File

@@ -0,0 +1,35 @@
use async_graphql::{Context, FieldResult, Object};
use sqlx::postgres::PgPool;
use crate::models::hersteller::Hersteller;
#[derive(Default)]
pub struct HerstellerQuery {
pub id: i32,
}
#[Object(extends)]
impl HerstellerQuery {
// #[graphql(external)]
// async fn id(&self) -> &i32 {
// &self.id
// }
// async fn modell<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Modell>> {
// let pool = ctx.data::<PgPool>().unwrap();
// let rows = Modell::read_by_typ(pool, &self.id).await?;
// Ok(rows)
// }
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)
}
}

12
src/queries/mod.rs Normal file
View File

@@ -0,0 +1,12 @@
pub mod hersteller;
pub mod modell;
pub mod typ;
use async_graphql::MergedObject;
#[derive(MergedObject, Default)]
pub struct Query(
typ::TypQuery,
modell::ModellQuery,
hersteller::HerstellerQuery,
);

34
src/queries/modell.rs Normal file
View File

@@ -0,0 +1,34 @@
use async_graphql::{Context, FieldResult, Object};
use sqlx::postgres::PgPool;
use crate::models::modell::Modell;
#[derive(Default)]
pub struct ModellQuery {
pub id: i32,
}
#[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 }
// }
}

41
src/queries/typ.rs Normal file
View File

@@ -0,0 +1,41 @@
use async_graphql::{Context, FieldResult, Object};
use sqlx::postgres::PgPool;
use crate::models::typ::Typ;
#[derive(Default)]
pub struct TypQuery {
pub id: i32,
}
#[Object(extends)]
impl TypQuery {
// #[graphql(external)]
// async fn id(&self) -> &i32 {
// &self.id
// }
// async fn modell<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Modell>> {
// let pool = ctx.data::<PgPool>().unwrap();
// let rows = Modell::read_by_typ(pool, &self.id).await?;
// Ok(rows)
// }
async fn typen<'a>(&self, ctx: &'a Context<'_>) -> FieldResult<Vec<Typ>> {
let pool = ctx.data::<PgPool>()?;
let rows = Typ::read_all(pool).await?;
Ok(rows)
}
async fn typ<'a>(&self, ctx: &'a Context<'_>, id: i32) -> FieldResult<Typ> {
let pool = ctx.data::<PgPool>()?;
let row = Typ::read_one(pool, &id).await?;
Ok(row)
}
// #[graphql(entity)]
// async fn find_typ_by_id<'a>(&self, ctx: &'a Context<'_>, id: i32) -> FieldResult<Typ> {
// let pool = ctx.data::<PgPool>().unwrap();
// let row = Typ::read_one(pool, &id).await?;
// Ok(row)
// }
}