migration GeräteEvents hinzugefügt; Entities erstellt

This commit is contained in:
2025-02-04 00:40:08 +01:00
parent e94bc657e8
commit 530b8c31d6
13 changed files with 359 additions and 6 deletions

View File

@@ -0,0 +1,43 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "benutzer")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(unique)]
pub e_mail: String,
#[sea_orm(unique)]
pub kennung: String,
pub password_hash: String,
pub nachname: String,
pub vorname: String,
pub erstellt_am: DateTimeWithTimeZone,
pub geaendert_am: DateTimeWithTimeZone,
pub ist_aktiv: bool,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(has_one = "super::hardware::Entity")]
Hardware,
#[sea_orm(has_many = "super::hardware_events::Entity")]
HardwareEvents,
}
impl Related<super::hardware::Entity> for Entity {
fn to() -> RelationDef {
Relation::Hardware.def()
}
}
impl Related<super::hardware_events::Entity> for Entity {
fn to() -> RelationDef {
Relation::HardwareEvents.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,42 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use super::sea_orm_active_enums::StatusType;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "hardware")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
pub name: String,
#[sea_orm(unique)]
pub seriennummer: String,
#[sea_orm(column_type = "Text")]
pub beschreibung: String,
pub status: StatusType,
#[sea_orm(unique)]
pub benutzer_id: Uuid,
pub erstellt_am: DateTimeWithTimeZone,
pub geaendert_am: DateTimeWithTimeZone,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::benutzer::Entity",
from = "Column::BenutzerId",
to = "super::benutzer::Column::Id",
on_update = "NoAction",
on_delete = "SetNull"
)]
Benutzer,
}
impl Related<super::benutzer::Entity> for Entity {
fn to() -> RelationDef {
Relation::Benutzer.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,41 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use super::sea_orm_active_enums::EventType;
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize, Deserialize)]
#[sea_orm(table_name = "hardware_events")]
pub struct Model {
#[sea_orm(primary_key, auto_increment = false)]
pub id: Uuid,
#[sea_orm(unique)]
pub hardware_id: Uuid,
#[sea_orm(unique)]
pub event: EventType,
pub payload: Json,
pub version: i32,
#[sea_orm(unique)]
pub erstellt_am: DateTimeWithTimeZone,
pub benutzer_id: Uuid,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {
#[sea_orm(
belongs_to = "super::benutzer::Entity",
from = "Column::BenutzerId",
to = "super::benutzer::Column::Id",
on_update = "NoAction",
on_delete = "SetNull"
)]
Benutzer,
}
impl Related<super::benutzer::Entity> for Entity {
fn to() -> RelationDef {
Relation::Benutzer.def()
}
}
impl ActiveModelBehavior for ActiveModel {}

View File

@@ -0,0 +1,8 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
pub mod prelude;
pub mod benutzer;
pub mod hardware;
pub mod hardware_events;
pub mod sea_orm_active_enums;

View File

@@ -0,0 +1,5 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
pub use super::benutzer::Entity as Benutzer;
pub use super::hardware::Entity as Hardware;
pub use super::hardware_events::Entity as HardwareEvents;

View File

@@ -0,0 +1,33 @@
//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.4
use sea_orm::entity::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "event_type")]
pub enum EventType {
#[sea_orm(string_value = "erstellt")]
Erstellt,
#[sea_orm(string_value = "geaendert")]
Geaendert,
#[sea_orm(string_value = "geloescht")]
Geloescht,
}
#[derive(Debug, Clone, PartialEq, Eq, EnumIter, DeriveActiveEnum, Copy, Serialize, Deserialize)]
#[sea_orm(rs_type = "String", db_type = "Enum", enum_name = "status_type")]
pub enum StatusType {
#[sea_orm(string_value = "verfuegbar")]
Verfuegbar,
#[sea_orm(string_value = "in_benutzung")]
InBenutzung,
#[sea_orm(string_value = "in_wartung")]
InWartung,
#[sea_orm(string_value = "in_reparatur")]
InReparatur,
#[sea_orm(string_value = "verloren")]
Verloren,
#[sea_orm(string_value = "defekt")]
Defekt,
#[sea_orm(string_value = "re_invest")]
ReInvest,
}

View File

@@ -0,0 +1,38 @@
#[derive(Debug, Serialize, Deserialize, Validate)]
pub struct ErstelleBenutzerDto {
#[validate(length(min = 10, max = 255))]
pub e_mail: String,
#[validate(length(min = 8, max = 8))]
pub kennung: String,
#[validate(length(max = 100))]
pub nachname: String,
#[validate(length(max = 100))]
pub vorname: String,
}
#[derive(Debug, Serialize)]
pub struct DeviceResponse {
pub id: Uuid,
pub name: String,
pub serial_number: String,
pub description: Option<String>,
pub status: String,
pub created_at: chrono::DateTime<chrono::Utc>,
}
// Conversion from Entity to Response Model
impl From<entities::devices::Model> for DeviceResponse {
fn from(entity: entities::devices::Model) -> Self {
Self {
id: entity.id,
name: entity.name,
serial_number: entity.serial_number,
description: entity.description,
status: entity.status,
created_at: entity.created_at,
}
}
}

View File

@@ -0,0 +1 @@
pub mod benutzer;

View File

@@ -0,0 +1 @@
pub use super::benutzer::ErstelleBenutzerDto as ErstelleBenutzer;