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)
|
|
|
|
}
|
2024-06-04 11:06:51 +02:00
|
|
|
async fn delete_modell(&self, ctx: &Context<'_>, id: i32) -> FieldResult<bool> {
|
2024-06-03 15:41:00 +02:00
|
|
|
let pool = ctx.data::<PgPool>()?;
|
2024-06-04 11:06:51 +02:00
|
|
|
Ok(Modell::delete(pool, &id).await?)
|
2024-06-03 15:41:00 +02:00
|
|
|
}
|
|
|
|
}
|