2024-06-24 22:46:04 +02:00
|
|
|
// SPDX-FileCopyrightText: 2024 Simon Bruder <simon@sbruder.de>
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
2024-07-11 21:50:03 +02:00
|
|
|
use time::OffsetDateTime;
|
2024-06-24 22:46:04 +02:00
|
|
|
use uuid::Uuid;
|
|
|
|
|
2024-07-12 17:23:17 +02:00
|
|
|
#[derive(Deserialize)]
|
|
|
|
pub enum EntityType {
|
|
|
|
Item,
|
|
|
|
ItemClass,
|
|
|
|
}
|
|
|
|
|
2024-07-11 17:25:01 +02:00
|
|
|
#[derive(Clone, Debug, Serialize, sqlx::FromRow)]
|
2024-06-24 22:46:04 +02:00
|
|
|
pub struct Item {
|
|
|
|
pub id: Uuid,
|
2024-07-10 01:14:49 +02:00
|
|
|
pub name: Option<String>,
|
2024-07-05 12:38:45 +02:00
|
|
|
pub parent: Option<Uuid>,
|
2024-07-07 13:48:31 +02:00
|
|
|
pub class: Uuid,
|
2024-07-11 21:50:03 +02:00
|
|
|
#[serde(with = "time::serde::iso8601")]
|
|
|
|
pub created_at: OffsetDateTime,
|
2024-07-12 00:50:32 +02:00
|
|
|
pub short_id: i32,
|
2024-06-24 22:46:04 +02:00
|
|
|
}
|
|
|
|
|
2024-07-11 17:25:01 +02:00
|
|
|
#[derive(Debug, Deserialize)]
|
2024-06-24 22:46:04 +02:00
|
|
|
pub struct NewItem {
|
2024-07-10 01:14:49 +02:00
|
|
|
#[serde(default)]
|
|
|
|
pub name: Option<String>,
|
2024-07-05 12:38:45 +02:00
|
|
|
#[serde(default)]
|
|
|
|
pub parent: Option<Uuid>,
|
2024-07-07 13:48:31 +02:00
|
|
|
pub class: Uuid,
|
|
|
|
}
|
|
|
|
|
2024-07-11 23:01:27 +02:00
|
|
|
// Its structure is not how it could ideally be
|
|
|
|
// (doubly nested Options where the original struct already has an Option>)
|
|
|
|
// because the intended usage (in a GET request parameter) does not allow such fine-grained types.
|
|
|
|
// TODO: this can be automated from NewItem with derive macro
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct NewItemForm {
|
|
|
|
#[serde(default)]
|
|
|
|
pub name: Option<String>,
|
|
|
|
#[serde(default)]
|
|
|
|
pub parent: Option<Uuid>,
|
|
|
|
pub class: Option<Uuid>,
|
|
|
|
}
|
|
|
|
|
2024-07-11 17:25:01 +02:00
|
|
|
#[derive(Clone, Debug, Serialize)]
|
2024-07-07 13:48:31 +02:00
|
|
|
pub struct ItemClass {
|
|
|
|
pub id: Uuid,
|
|
|
|
pub name: String,
|
|
|
|
#[serde(skip_serializing_if = "Option::is_none")]
|
|
|
|
pub parent: Option<Uuid>,
|
2024-07-11 21:50:03 +02:00
|
|
|
#[serde(with = "time::serde::iso8601")]
|
|
|
|
pub created_at: OffsetDateTime,
|
2024-07-07 13:48:31 +02:00
|
|
|
}
|
|
|
|
|
2024-07-11 17:25:01 +02:00
|
|
|
#[derive(Debug, Deserialize)]
|
2024-07-07 13:48:31 +02:00
|
|
|
pub struct NewItemClass {
|
|
|
|
pub name: String,
|
|
|
|
#[serde(default)]
|
|
|
|
pub parent: Option<Uuid>,
|
2024-06-24 22:46:04 +02:00
|
|
|
}
|
2024-07-11 23:01:27 +02:00
|
|
|
|
|
|
|
// see NewItemForm
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
pub struct NewItemClassForm {
|
|
|
|
pub name: Option<String>,
|
|
|
|
#[serde(default)]
|
|
|
|
pub parent: Option<Uuid>,
|
|
|
|
}
|