// SPDX-FileCopyrightText: 2024 Simon Bruder // // SPDX-License-Identifier: AGPL-3.0-or-later use serde::{Deserialize, Serialize}; use time::OffsetDateTime; use uuid::Uuid; #[derive(Deserialize)] pub enum EntityType { Item, ItemClass, } #[derive(Clone, Debug, Serialize, sqlx::FromRow)] pub struct Item { pub id: Uuid, pub name: Option, pub parent: Option, pub class: Uuid, #[serde(with = "time::serde::iso8601")] pub created_at: OffsetDateTime, pub short_id: i32, } #[derive(Debug, Deserialize)] pub struct NewItem { #[serde(default)] pub name: Option, #[serde(default)] pub parent: Option, pub class: Uuid, } // 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, #[serde(default)] pub parent: Option, pub class: Option, } #[derive(Clone, Debug, Serialize)] pub struct ItemClass { pub id: Uuid, pub name: String, #[serde(skip_serializing_if = "Option::is_none")] pub parent: Option, #[serde(with = "time::serde::iso8601")] pub created_at: OffsetDateTime, } #[derive(Debug, Deserialize)] pub struct NewItemClass { pub name: String, #[serde(default)] pub parent: Option, } // see NewItemForm #[derive(Debug, Deserialize)] pub struct NewItemClassForm { pub name: Option, #[serde(default)] pub parent: Option, }