34 lines
885 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<'_>,
2024-06-04 15:38:07 +02:00
input: ModellCreateInput,
2024-06-03 15:41:00 +02:00
) -> FieldResult<Modell> {
let pool = ctx.data::<PgPool>()?;
2024-06-04 15:38:07 +02:00
let row = Modell::create(pool, &input).await?;
2024-06-03 15:41:00 +02:00
Ok(row)
}
async fn update_modell(
&self,
ctx: &Context<'_>,
2024-06-04 15:38:07 +02:00
input: ModellUpdateInput,
2024-06-03 15:41:00 +02:00
) -> FieldResult<Modell> {
let pool = ctx.data::<PgPool>()?;
2024-06-04 15:38:07 +02:00
let row = Modell::update(pool, &input).await?;
2024-06-03 15:41:00 +02:00
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
}
}