36 lines
901 B
Rust
Raw Normal View History

2024-06-03 15:41:00 +02:00
use crate::models::modell::*;
use async_graphql::{Context, FieldResult};
use sqlx::postgres::PgPool;
#[derive(Default)]
pub struct ModellMutation;
#[async_graphql::Object]
impl ModellMutation {
async fn create_modell(
&self,
ctx: &Context<'_>,
modell: ModellCreateInput,
) -> FieldResult<Modell> {
let pool = ctx.data::<PgPool>()?;
let row = Modell::create(pool, &modell).await?;
Ok(row)
}
async fn update_modell(
&self,
ctx: &Context<'_>,
modell: ModellUpdateInput,
) -> FieldResult<Modell> {
let pool = ctx.data::<PgPool>()?;
let row = Modell::update(pool, &modell).await?;
Ok(row)
}
async fn delete_typ(&self, ctx: &Context<'_>, id: i32) -> FieldResult<bool> {
let pool = ctx.data::<PgPool>()?;
Modell::delete(pool, &id).await?;
Ok(true)
}
}