refactoring rolle

This commit is contained in:
keiner 2024-06-21 23:08:18 +02:00
parent 44931afbe7
commit a290bcceb3
11 changed files with 53 additions and 9 deletions

View File

@ -1,5 +1,5 @@
pub mod entity;
pub mod model;
pub mod mutation;
pub mod repository;
pub mod service;

View File

@ -1,5 +1,6 @@
mod create_rolle_input;
mod rolle;
mod update_rolle_input;
mod rolle_create_input;
mod rolle_update_input;
pub use create_rolle_input::CreateRolleInput;
pub use rolle::Rolle;
pub use rolle_create_input::RolleCreateInput;

View File

@ -10,6 +10,9 @@ pub struct Rolle {
/// Wann die Rolle erstellt wurde
pub created_at: Time,
/// Wann die Rolle geändert wurde
pub updated_at: Time,
/// Der Name einer Rolle
pub name: String,
}

View File

@ -1,7 +1,7 @@
use async_graphql::InputObject;
#[derive(InputObject)]
pub struct CreateRolleInput {
pub struct RolleCreateInput {
/// Der Name einer Rolle
pub name: String,
}

View File

@ -3,7 +3,7 @@ use async_graphql::InputObject;
use crate::scalar::Id;
#[derive(InputObject)]
pub struct UpdateRolleInput {
pub struct RolleUpdateInput {
/// Die ID einer Rolle
pub id: Id,

View File

@ -0,0 +1,35 @@
use super::model::*;
use async_graphql::{Context, FieldResult};
use sqlx::postgres::PgPool;
#[derive(Default)]
pub struct RolleMutation;
#[async_graphql::Object]
impl RolleMutation {
async fn create_rollen(
&self,
ctx: &Context<'_>,
input: RolleCreateInput,
) -> FieldResult<Rolle> {
let pool = ctx.data::<PgPool>()?;
todo!();
// let row = Rolle::create(pool, &input).await?;
// Ok(row)
}
// async fn update_rollen(
// &self,
// ctx: &Context<'_>,
// input: RolleUpdateInput,
// ) -> FieldResult<Rolle> {
// let pool = ctx.data::<PgPool>()?;
// let row = Rolle::update(pool, &input).await?;
// Ok(row)
// }
//
// async fn delete_rollen(&self, ctx: &Context<'_>, id: i32) -> FieldResult<bool> {
// let pool = ctx.data::<PgPool>()?;
// Ok(Rolle::delete(pool, &id).await?)
// }
}

View File

@ -1,7 +1,7 @@
mod create_rolle;
mod delete_rolle;
mod find_all_rolle;
mod find_rolle;
mod find_rolle_by_id;
mod update_rolle;
#[derive(Debug, Clone)]

View File

@ -1,6 +1,7 @@
use anyhow::Error;
use super::Repository;
// use crate::domain::rolle::model;
use crate::{database::Queryer, domain::rolle::entity};
impl Repository {

View File

@ -4,10 +4,10 @@ use ulid::Ulid;
use super::Service;
use crate::domain::rolle::entity;
use crate::domain::rolle::model::CreateRolleInput;
use crate::domain::rolle::model::RolleCreateInput;
impl Service {
pub async fn create_rolle(&self, input: CreateRolleInput) -> Result<entity::Rolle, Error> {
pub async fn create_rolle(&self, input: RolleCreateInput) -> Result<entity::Rolle, Error> {
// let username_exists = self.check_username_exists(&self.db, &input.name).await?;
// if username_exists {
// return Err(Error::UsernameAlreadyExists.into());

View File

@ -14,12 +14,16 @@ pub struct Hersteller {
#[derive(InputObject, Debug)]
pub struct HerstellerCreateInput {
/// Der Name eines Herstellers
pub name: String,
}
#[derive(InputObject, Debug)]
pub struct HerstellerUpdateInput {
/// Die Datenbank-ID
pub id: i32,
/// Der Name eines Herstellers
pub name: Option<String>,
}