typ refactor
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
CREATE TABLE IF NOT EXISTS typen (
|
CREATE TABLE IF NOT EXISTS typen (
|
||||||
id UUID PRIMARY KEY,
|
typ_id UUID PRIMARY KEY,
|
||||||
|
id CHAR(26) UNIQUE NOT NULL,
|
||||||
typname VARCHAR NOT NULL,
|
typname VARCHAR NOT NULL,
|
||||||
erstellt_am TIMESTAMP WITH TIME ZONE NOT NULL,
|
erstellt_am TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
geaendert_am TIMESTAMP WITH TIME ZONE NOT NULL
|
geaendert_am TIMESTAMP WITH TIME ZONE NOT NULL
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
CREATE TABLE IF NOT EXISTS hersteller (
|
CREATE TABLE IF NOT EXISTS hersteller (
|
||||||
id UUID PRIMARY KEY,
|
hersteller_id UUID PRIMARY KEY,
|
||||||
|
id CHAR(26) UNIQUE NOT NULL,
|
||||||
herstellername VARCHAR NOT NULL,
|
herstellername VARCHAR NOT NULL,
|
||||||
erstellt_am TIMESTAMP WITH TIME ZONE NOT NULL,
|
erstellt_am TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
geaendert_am TIMESTAMP WITH TIME ZONE NOT NULL
|
geaendert_am TIMESTAMP WITH TIME ZONE NOT NULL
|
||||||
|
|||||||
@@ -5,12 +5,12 @@ CREATE TABLE IF NOT EXISTS modelle (
|
|||||||
hersteller_id UUID,
|
hersteller_id UUID,
|
||||||
|
|
||||||
CONSTRAINT fk_typ FOREIGN KEY (typ_id)
|
CONSTRAINT fk_typ FOREIGN KEY (typ_id)
|
||||||
REFERENCES typen (id)
|
REFERENCES typen (typ_id)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION,
|
ON UPDATE NO ACTION,
|
||||||
|
|
||||||
CONSTRAINT fk_hersteller FOREIGN KEY (hersteller_id)
|
CONSTRAINT fk_hersteller FOREIGN KEY (hersteller_id)
|
||||||
REFERENCES hersteller (id)
|
REFERENCES hersteller (hersteller_id)
|
||||||
ON DELETE NO ACTION
|
ON DELETE NO ACTION
|
||||||
ON UPDATE NO ACTION
|
ON UPDATE NO ACTION
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
CREATE TABLE IF NOT EXISTS liegenschaften (
|
CREATE TABLE IF NOT EXISTS liegenschaften (
|
||||||
id_liegenschaft UUID PRIMARY KEY,
|
id_liegenschaft UUID PRIMARY KEY,
|
||||||
id VARCHAR UNIQUE,
|
id CHAR(26) UNIQUE,
|
||||||
liegenschaftname VARCHAR NOT NULL,
|
liegenschaftname VARCHAR NOT NULL,
|
||||||
erstellt_am TIMESTAMP WITH TIME ZONE NOT NULL,
|
erstellt_am TIMESTAMP WITH TIME ZONE NOT NULL,
|
||||||
geaendert_am TIMESTAMP WITH TIME ZONE NOT NULL
|
geaendert_am TIMESTAMP WITH TIME ZONE NOT NULL
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
pub mod dataloader;
|
pub mod dataloader;
|
||||||
pub mod entity;
|
pub mod entity;
|
||||||
pub mod model;
|
pub mod model;
|
||||||
|
pub mod mutation;
|
||||||
pub mod queries;
|
pub mod queries;
|
||||||
pub mod repository;
|
pub mod repository;
|
||||||
pub mod service;
|
pub mod service;
|
||||||
|
|||||||
@@ -1,2 +1,6 @@
|
|||||||
pub mod typ;
|
pub mod typ;
|
||||||
pub use typ::Typ;
|
|
||||||
|
// pub use typ::Typ;
|
||||||
|
pub use typ::TypErstellen;
|
||||||
|
pub use typ::TypLoeschen;
|
||||||
|
pub use typ::TypUpdate;
|
||||||
|
|||||||
@@ -1,8 +1,19 @@
|
|||||||
use crate::scalar::{Id, Time};
|
use crate::scalar::{Id, Time, Ulid};
|
||||||
|
|
||||||
pub struct Typ {
|
pub struct TypErstellen {
|
||||||
pub id: Id,
|
pub typ_id: Id,
|
||||||
|
pub id: Ulid,
|
||||||
pub typname: String,
|
pub typname: String,
|
||||||
pub erstellt_am: Option<Time>,
|
pub erstellt_am: Time,
|
||||||
pub geaendert_am: Option<Time>,
|
pub geaendert_am: Time,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TypLoeschen {
|
||||||
|
pub id: Ulid,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TypUpdate {
|
||||||
|
pub id: Ulid,
|
||||||
|
pub typname: String,
|
||||||
|
pub geaendert_am: Time,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,20 +1,20 @@
|
|||||||
use async_graphql::{ComplexObject, SimpleObject};
|
use async_graphql::{ComplexObject, SimpleObject};
|
||||||
|
|
||||||
use crate::scalar::{Id, Time};
|
use crate::scalar::{Time, Ulid};
|
||||||
|
|
||||||
#[derive(sqlx::FromRow, SimpleObject, Clone, Debug)]
|
#[derive(sqlx::FromRow, SimpleObject, Clone, Debug)]
|
||||||
#[graphql(complex)]
|
#[graphql(complex)]
|
||||||
pub struct Typ {
|
pub struct Typ {
|
||||||
/// Die UUID einer Typ
|
/// Die Ulid eines Gerätetypen
|
||||||
pub id: Id,
|
pub id: Ulid,
|
||||||
|
|
||||||
/// Der Typname
|
/// Der Typname
|
||||||
pub typname: String,
|
pub typname: String,
|
||||||
|
|
||||||
/// Wann die Typ erstellt wurde
|
/// Wann der Typ erstellt wurde
|
||||||
pub erstellt_am: Time,
|
pub erstellt_am: Time,
|
||||||
|
|
||||||
/// Wann die Typ geaendert wurde
|
/// Wann der Typ geaendert wurde
|
||||||
pub geaendert_am: Time,
|
pub geaendert_am: Time,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
use async_graphql::InputObject;
|
use async_graphql::InputObject;
|
||||||
|
|
||||||
use crate::scalar::Id;
|
use crate::scalar::Ulid;
|
||||||
|
|
||||||
#[derive(InputObject)]
|
#[derive(InputObject)]
|
||||||
pub struct TypLoeschenInput {
|
pub struct TypLoeschenInput {
|
||||||
/// Die ID einer Typ
|
/// Die ULID von einem Typ
|
||||||
pub id: Id,
|
pub id: Ulid,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
use crate::scalar::Id;
|
|
||||||
use async_graphql::InputObject;
|
use async_graphql::InputObject;
|
||||||
|
|
||||||
|
use crate::scalar::Ulid;
|
||||||
|
|
||||||
#[derive(InputObject)]
|
#[derive(InputObject)]
|
||||||
pub struct TypUpdateInput {
|
pub struct TypUpdateInput {
|
||||||
/// Die ID einer Typ
|
/// Die ULID von einem Typen
|
||||||
pub id: Id,
|
pub id: Ulid,
|
||||||
|
|
||||||
/// Der Name einer Typ
|
/// Der Name einer Typ
|
||||||
pub typname: String,
|
pub typname: String,
|
||||||
|
|||||||
3
src/domain/typ/mutation.rs
Normal file
3
src/domain/typ/mutation.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub mod typ;
|
||||||
|
|
||||||
|
pub use typ::TypMutation;
|
||||||
@@ -12,9 +12,9 @@ pub struct TypMutation;
|
|||||||
#[async_graphql::Object]
|
#[async_graphql::Object]
|
||||||
impl TypMutation {
|
impl TypMutation {
|
||||||
async fn erstelle_typ(&self, ctx: &Context<'_>, input: TypErstelleInput) -> FieldResult<Typ> {
|
async fn erstelle_typ(&self, ctx: &Context<'_>, input: TypErstelleInput) -> FieldResult<Typ> {
|
||||||
let pool = ctx.data::<PgPool>()?;
|
let pool = ctx.data::<PgPool>()?.clone();
|
||||||
|
|
||||||
let typ = Service::new(pool.clone()).typ_erstellen(input).await?;
|
let typ = Service::new(pool).typ_erstellen(input).await?;
|
||||||
Ok(typ)
|
Ok(typ)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,6 +40,7 @@ impl TypMutation {
|
|||||||
|
|
||||||
async fn loesche_typ(&self, ctx: &Context<'_>, input: TypLoeschenInput) -> FieldResult<Typ> {
|
async fn loesche_typ(&self, ctx: &Context<'_>, input: TypLoeschenInput) -> FieldResult<Typ> {
|
||||||
let pool = ctx.data::<PgPool>()?;
|
let pool = ctx.data::<PgPool>()?;
|
||||||
|
|
||||||
let typ = Service::new(pool.clone()).typ_loeschen(input).await?;
|
let typ = Service::new(pool.clone()).typ_loeschen(input).await?;
|
||||||
Ok(typ)
|
Ok(typ)
|
||||||
}
|
}
|
||||||
@@ -4,30 +4,33 @@ use super::Repository;
|
|||||||
use crate::database::Queryer;
|
use crate::database::Queryer;
|
||||||
use crate::domain::typ::entity;
|
use crate::domain::typ::entity;
|
||||||
use crate::domain::typ::model::{self};
|
use crate::domain::typ::model::{self};
|
||||||
use crate::scalar::{Id, Time};
|
use crate::scalar::{Id, Time, Ulid};
|
||||||
|
|
||||||
impl Repository {
|
impl Repository {
|
||||||
pub async fn typ_viele_erstellen<'c, C: Queryer<'c>>(
|
pub async fn typ_viele_erstellen<'c, C: Queryer<'c>>(
|
||||||
&self,
|
&self,
|
||||||
db: C,
|
db: C,
|
||||||
typen: &[entity::Typ], // input: &[Typ],
|
typen: &[entity::TypErstellen], // input: &[Typ],
|
||||||
) -> Result<Vec<model::Typ>, Error> {
|
) -> Result<Vec<model::Typ>, Error> {
|
||||||
let id: Vec<Id> = typen.iter().map(|t| t.id).collect();
|
let typ_id: Vec<Id> = typen.iter().map(|t| t.typ_id).collect();
|
||||||
|
let id: Vec<Ulid> = typen.iter().map(|t| t.id.to_string()).collect();
|
||||||
let typnamen: Vec<String> = typen.iter().map(|t| t.typname.clone()).collect();
|
let typnamen: Vec<String> = typen.iter().map(|t| t.typname.clone()).collect();
|
||||||
let erstellt_am: Vec<Option<Time>> = typen.iter().map(|t| t.erstellt_am).collect();
|
let erstellt_am: Vec<Time> = typen.iter().map(|t| t.erstellt_am).collect();
|
||||||
let geaendert_am: Vec<Option<Time>> = typen.iter().map(|t| t.geaendert_am).collect();
|
let geaendert_am: Vec<Time> = typen.iter().map(|t| t.geaendert_am).collect();
|
||||||
|
|
||||||
const QUERY: &str = r#"
|
const QUERY: &str = r#"
|
||||||
INSERT INTO typen (id, typname, erstellt_am, geaendert_am)
|
INSERT INTO typen (typ_id, id, typname, erstellt_am, geaendert_am)
|
||||||
SELECT * FROM UNNEST(
|
SELECT * FROM UNNEST(
|
||||||
$1::uuid[],
|
$1::uuid[],
|
||||||
$2::text[],
|
$2::text[],
|
||||||
$3::TIMESTAMP[],
|
$3::text[],
|
||||||
$4::TIMESTAMP[]
|
$4::TIMESTAMP[],
|
||||||
|
$5::TIMESTAMP[]
|
||||||
) RETURNING id, erstellt_am, geaendert_am, typname;
|
) RETURNING id, erstellt_am, geaendert_am, typname;
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let rows = sqlx::query_as::<_, model::Typ>(QUERY)
|
let rows = sqlx::query_as::<_, model::Typ>(QUERY)
|
||||||
|
.bind(typ_id)
|
||||||
.bind(id)
|
.bind(id)
|
||||||
.bind(typnamen)
|
.bind(typnamen)
|
||||||
.bind(erstellt_am)
|
.bind(erstellt_am)
|
||||||
|
|||||||
@@ -8,16 +8,17 @@ impl Repository {
|
|||||||
pub async fn typ_erstellen<'c, C: Queryer<'c>>(
|
pub async fn typ_erstellen<'c, C: Queryer<'c>>(
|
||||||
&self,
|
&self,
|
||||||
db: C,
|
db: C,
|
||||||
typ: &entity::Typ,
|
typ: &entity::TypErstellen,
|
||||||
) -> Result<model::Typ, Error> {
|
) -> Result<model::Typ, Error> {
|
||||||
const QUERY: &str = r#"
|
const QUERY: &str = r#"
|
||||||
INSERT INTO typen (id, erstellt_am, geaendert_am, typname) VALUES (
|
INSERT INTO typen (typ_id, id, erstellt_am, geaendert_am, typname) VALUES (
|
||||||
$1, $2, $3, $4
|
$1, $2, $3, $4, $5
|
||||||
) RETURNING id, erstellt_am, geaendert_am, typname;
|
) RETURNING id, erstellt_am, geaendert_am, typname;
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
|
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
|
||||||
.bind(typ.id)
|
.bind(typ.typ_id)
|
||||||
|
.bind(typ.id.to_string())
|
||||||
.bind(typ.erstellt_am)
|
.bind(typ.erstellt_am)
|
||||||
.bind(typ.geaendert_am)
|
.bind(typ.geaendert_am)
|
||||||
.bind(&typ.typname)
|
.bind(&typ.typname)
|
||||||
|
|||||||
@@ -8,14 +8,14 @@ impl Repository {
|
|||||||
pub async fn typ_loeschen<'c, C: Queryer<'c>>(
|
pub async fn typ_loeschen<'c, C: Queryer<'c>>(
|
||||||
&self,
|
&self,
|
||||||
db: C,
|
db: C,
|
||||||
typ: &entity::Typ,
|
typ: &entity::TypLoeschen,
|
||||||
) -> Result<model::Typ, Error> {
|
) -> Result<model::Typ, Error> {
|
||||||
const QUERY: &str = r#"
|
const QUERY: &str = r#"
|
||||||
DELETE FROM typen WHERE id=$1 RETURNING id, erstellt_am, geaendert_am, typname;
|
DELETE FROM typen WHERE id=$1 RETURNING id, erstellt_am, geaendert_am, typname;
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
|
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
|
||||||
.bind(typ.id)
|
.bind(typ.id.to_string())
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ impl Repository {
|
|||||||
pub async fn typ_update<'c, C: Queryer<'c>>(
|
pub async fn typ_update<'c, C: Queryer<'c>>(
|
||||||
&self,
|
&self,
|
||||||
db: C,
|
db: C,
|
||||||
typ: &entity::Typ,
|
typ: &entity::TypUpdate,
|
||||||
) -> Result<model::Typ, Error> {
|
) -> Result<model::Typ, Error> {
|
||||||
const QUERY: &str = r#"
|
const QUERY: &str = r#"
|
||||||
UPDATE typen
|
UPDATE typen
|
||||||
@@ -17,7 +17,7 @@ impl Repository {
|
|||||||
"#;
|
"#;
|
||||||
|
|
||||||
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
|
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
|
||||||
.bind(typ.id)
|
.bind(typ.id.to_string())
|
||||||
.bind(typ.geaendert_am)
|
.bind(typ.geaendert_am)
|
||||||
.bind(&typ.typname)
|
.bind(&typ.typname)
|
||||||
.fetch_one(db)
|
.fetch_one(db)
|
||||||
|
|||||||
@@ -10,14 +10,15 @@ use crate::domain::typ::{
|
|||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
pub async fn typ_erstellen(&self, input: TypErstelleInput) -> Result<model::Typ, Error> {
|
pub async fn typ_erstellen(&self, input: TypErstelleInput) -> Result<model::Typ, Error> {
|
||||||
let typ_input = entity::Typ {
|
let typ_erstellen = entity::TypErstellen {
|
||||||
id: Ulid::new().into(),
|
typ_id: Ulid::new().into(),
|
||||||
|
id: Ulid::new().to_string(),
|
||||||
typname: input.typname,
|
typname: input.typname,
|
||||||
erstellt_am: Some(Utc::now()),
|
erstellt_am: Utc::now(),
|
||||||
geaendert_am: Some(Utc::now()),
|
geaendert_am: Utc::now(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let typ = self.repo.typ_erstellen(&self.db, &typ_input).await?;
|
let typ = self.repo.typ_erstellen(&self.db, &typ_erstellen).await?;
|
||||||
Ok(typ)
|
Ok(typ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,19 +13,20 @@ impl Service {
|
|||||||
&self,
|
&self,
|
||||||
input: &[TypErstelleInput],
|
input: &[TypErstelleInput],
|
||||||
) -> Result<Vec<model::Typ>, Error> {
|
) -> Result<Vec<model::Typ>, Error> {
|
||||||
let typen_input: Vec<entity::Typ> = input
|
let typen_erstellen: Vec<entity::TypErstellen> = input
|
||||||
.iter()
|
.iter()
|
||||||
.map(|t| entity::Typ {
|
.map(|t| entity::TypErstellen {
|
||||||
id: Ulid::new().into(),
|
typ_id: Ulid::new().into(),
|
||||||
|
id: Ulid::new().to_string(),
|
||||||
typname: t.typname.clone(),
|
typname: t.typname.clone(),
|
||||||
erstellt_am: Some(Utc::now()),
|
erstellt_am: Utc::now(),
|
||||||
geaendert_am: Some(Utc::now()),
|
geaendert_am: Utc::now(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let typen = self
|
let typen = self
|
||||||
.repo
|
.repo
|
||||||
.typ_viele_erstellen(&self.db, &typen_input)
|
.typ_viele_erstellen(&self.db, &typen_erstellen)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Ok(typen)
|
Ok(typen)
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
use chrono::Utc;
|
|
||||||
|
|
||||||
use super::Service;
|
use super::Service;
|
||||||
use crate::domain::typ::{
|
use crate::domain::typ::{
|
||||||
@@ -9,14 +8,9 @@ use crate::domain::typ::{
|
|||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
pub async fn typ_loeschen(&self, input: TypLoeschenInput) -> Result<model::Typ, Error> {
|
pub async fn typ_loeschen(&self, input: TypLoeschenInput) -> Result<model::Typ, Error> {
|
||||||
let typ_input = entity::Typ {
|
let typ_loeschen = entity::TypLoeschen { id: input.id };
|
||||||
id: input.id,
|
|
||||||
typname: String::new(),
|
|
||||||
erstellt_am: None,
|
|
||||||
geaendert_am: Some(Utc::now()),
|
|
||||||
};
|
|
||||||
|
|
||||||
let typ = self.repo.typ_loeschen(&self.db, &typ_input).await?;
|
let typ = self.repo.typ_loeschen(&self.db, &typ_loeschen).await?;
|
||||||
Ok(typ)
|
Ok(typ)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,10 @@ use crate::domain::typ::{
|
|||||||
|
|
||||||
impl Service {
|
impl Service {
|
||||||
pub async fn typ_update(&self, input: TypUpdateInput) -> Result<model::Typ, Error> {
|
pub async fn typ_update(&self, input: TypUpdateInput) -> Result<model::Typ, Error> {
|
||||||
let typ_input = entity::Typ {
|
let typ_input = entity::TypUpdate {
|
||||||
id: input.id,
|
id: input.id,
|
||||||
typname: input.typname,
|
typname: input.typname,
|
||||||
erstellt_am: None,
|
geaendert_am: Utc::now(),
|
||||||
geaendert_am: Some(Utc::now()),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let typ = self.repo.typ_update(&self.db, &typ_input).await?;
|
let typ = self.repo.typ_update(&self.db, &typ_input).await?;
|
||||||
|
|||||||
@@ -4,13 +4,14 @@ pub mod gruppe;
|
|||||||
// pub mod modell;
|
// pub mod modell;
|
||||||
pub mod liegenschaft;
|
pub mod liegenschaft;
|
||||||
pub mod rolle;
|
pub mod rolle;
|
||||||
pub mod typ;
|
|
||||||
|
|
||||||
use async_graphql::MergedObject;
|
use async_graphql::MergedObject;
|
||||||
|
|
||||||
|
use crate::domain::typ::mutation::TypMutation;
|
||||||
|
|
||||||
#[derive(MergedObject, Default)]
|
#[derive(MergedObject, Default)]
|
||||||
pub struct Mutation(
|
pub struct Mutation(
|
||||||
typ::TypMutation,
|
TypMutation,
|
||||||
// hersteller::HerstellerMutation,
|
// hersteller::HerstellerMutation,
|
||||||
// modell::ModellMutation,
|
// modell::ModellMutation,
|
||||||
benutzer::BenutzerMutation,
|
benutzer::BenutzerMutation,
|
||||||
|
|||||||
@@ -8,3 +8,8 @@ pub type Time = chrono::DateTime<chrono::Utc>;
|
|||||||
/// The ID type appears in a JSON response as a String; however, it is not intended to be human-readable.
|
/// The ID type appears in a JSON response as a String; however, it is not intended to be human-readable.
|
||||||
/// When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.
|
/// When expected as an input type, any string (such as "4") or integer (such as 4) input value will be accepted as an ID.
|
||||||
pub type Id = Uuid;
|
pub type Id = Uuid;
|
||||||
|
|
||||||
|
/// ödsklfjsdf
|
||||||
|
/// debug_assert_eq!(ödsklfjsdfasdfas
|
||||||
|
/// ödsklfjsdfasdfasdfsa,
|
||||||
|
pub type Ulid = String;
|
||||||
|
|||||||
Reference in New Issue
Block a user