ulid als scalar hinzugefügt

This commit is contained in:
2026-06-04 22:42:57 +02:00
parent b3b7b75ea8
commit 5fb2b3666f
14 changed files with 163 additions and 20 deletions

View File

@@ -2,8 +2,15 @@ use async_graphql::{ComplexObject, SimpleObject};
use crate::scalar::{Time, Ulid};
#[derive(sqlx::FromRow, SimpleObject, Clone, Debug)]
#[graphql(complex)]
// #[derive(Debug, sqlx::FromRow)]
// pub struct TypDb {
// pub id: String,
// pub typname: String,
// pub erstellt_am: Time,
// pub geaendert_am: Time,
// }
#[derive(SimpleObject, Clone, sqlx::FromRow)]
pub struct Typ {
/// Die Ulid eines Gerätetypen
pub id: Ulid,
@@ -18,5 +25,16 @@ pub struct Typ {
pub geaendert_am: Time,
}
// impl From<TypDb> for Typ {
// fn from(db: TypDb) -> Self {
// Self {
// id: Ulid(ulid::Ulid::from_string(&db.id).expect("stored ULID is valid")),
// typname: db.typname,
// erstellt_am: db.erstellt_am,
// geaendert_am: db.geaendert_am,
// }
// }
// }
#[ComplexObject]
impl Typ {}

View File

@@ -11,6 +11,8 @@ impl Repository {
let typen = sqlx::query_as::<_, model::Typ>(QUERY).fetch_all(db).await?;
// let typen: Vec<model::Typ> = typen.into_iter().map(model::Typ::from).collect();
Ok(typen)
}
}

View File

@@ -19,6 +19,7 @@ impl Repository {
.bind(id)
.fetch_one(db)
.await?;
// .map(model::Typ::from)?;
Ok(row)
}

View File

@@ -13,7 +13,7 @@ impl Repository {
typen: &[entity::TypErstellen], // input: &[Typ],
) -> Result<Vec<model::Typ>, Error> {
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 id: Vec<Ulid> = typen.iter().map(|t| t.id).collect();
let typnamen: Vec<String> = typen.iter().map(|t| t.typname.clone()).collect();
let erstellt_am: Vec<Time> = typen.iter().map(|t| t.erstellt_am).collect();
let geaendert_am: Vec<Time> = typen.iter().map(|t| t.geaendert_am).collect();
@@ -38,6 +38,8 @@ impl Repository {
.fetch_all(db)
.await?;
// let rows: Vec<model::Typ> = rows.into_iter().map(model::Typ::from).collect();
Ok(rows)
}
}

View File

@@ -18,12 +18,13 @@ impl Repository {
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
.bind(typ.typ_id)
.bind(typ.id.to_string())
.bind(typ.id)
.bind(typ.erstellt_am)
.bind(typ.geaendert_am)
.bind(&typ.typname)
.fetch_one(db)
.await?;
// .map(model::Typ::from)?;
Ok(typ)
}

View File

@@ -15,9 +15,10 @@ impl Repository {
"#;
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
.bind(typ.id.to_string())
.bind(typ.id)
.fetch_one(db)
.await?;
// .map(model::Typ::from)?;
Ok(typ)
}

View File

@@ -17,11 +17,12 @@ impl Repository {
"#;
let typ = sqlx::query_as::<_, model::Typ>(QUERY)
.bind(typ.id.to_string())
.bind(typ.id)
.bind(typ.geaendert_am)
.bind(&typ.typname)
.fetch_one(db)
.await?;
// .map(model::Typ::from)?;
Ok(typ)
}

View File

@@ -1,18 +1,18 @@
use anyhow::Error;
use chrono::Utc;
use ulid::Ulid;
use super::Service;
use crate::domain::typ::{
entity,
model::{self, TypErstelleInput},
};
use crate::scalar::Ulid;
impl Service {
pub async fn typ_erstellen(&self, input: TypErstelleInput) -> Result<model::Typ, Error> {
let typ_erstellen = entity::TypErstellen {
typ_id: Ulid::new().into(),
id: Ulid::new().to_string(),
typ_id: ulid::Ulid::new().into(),
id: Ulid(ulid::Ulid::new()),
typname: input.typname,
erstellt_am: Utc::now(),
geaendert_am: Utc::now(),

View File

@@ -1,11 +1,13 @@
use anyhow::Error;
use chrono::Utc;
use ulid::Ulid;
use super::Service;
use crate::domain::typ::{
entity,
model::{self, TypErstelleInput},
use crate::{
domain::typ::{
entity,
model::{self, TypErstelleInput},
},
scalar::Ulid,
};
impl Service {
@@ -16,8 +18,8 @@ impl Service {
let typen_erstellen: Vec<entity::TypErstellen> = input
.iter()
.map(|t| entity::TypErstellen {
typ_id: Ulid::new().into(),
id: Ulid::new().to_string(),
typ_id: ulid::Ulid::new().into(),
id: Ulid(ulid::Ulid::new()),
typname: t.typname.clone(),
erstellt_am: Utc::now(),
geaendert_am: Utc::now(),