2024-06-04 15:38:07 +02:00

34 lines
885 B
Rust

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<'_>,
input: ModellCreateInput,
) -> FieldResult<Modell> {
let pool = ctx.data::<PgPool>()?;
let row = Modell::create(pool, &input).await?;
Ok(row)
}
async fn update_modell(
&self,
ctx: &Context<'_>,
input: ModellUpdateInput,
) -> FieldResult<Modell> {
let pool = ctx.data::<PgPool>()?;
let row = Modell::update(pool, &input).await?;
Ok(row)
}
async fn delete_modell(&self, ctx: &Context<'_>, id: i32) -> FieldResult<bool> {
let pool = ctx.data::<PgPool>()?;
Ok(Modell::delete(pool, &id).await?)
}
}