// SPDX-FileCopyrightText: 2024 Simon Bruder // // SPDX-License-Identifier: AGPL-3.0-or-later use diesel::prelude::*; use serde::{Deserialize, Serialize}; use uuid::Uuid; use crate::schema::*; #[derive(Clone, Debug, Queryable, Selectable, Insertable, Serialize)] #[diesel(table_name = items)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct Item { pub id: Uuid, pub name: Option, pub parent: Option, pub class: Uuid, } #[derive(Debug, Insertable, Deserialize, AsChangeset)] #[diesel(table_name = items)] #[diesel(check_for_backend(diesel::pg::Pg))] #[diesel(treat_none_as_null = true)] pub struct NewItem { #[serde(default)] pub name: Option, #[serde(default)] pub parent: Option, pub class: Uuid, } #[derive(Clone, Debug, Queryable, Selectable, Insertable, Serialize)] #[diesel(table_name = item_classes)] #[diesel(check_for_backend(diesel::pg::Pg))] pub struct ItemClass { pub id: Uuid, pub name: String, #[serde(skip_serializing_if = "Option::is_none")] pub parent: Option, } #[derive(Debug, Insertable, Deserialize, AsChangeset)] #[diesel(table_name = item_classes)] #[diesel(check_for_backend(diesel::pg::Pg))] #[diesel(treat_none_as_null = true)] pub struct NewItemClass { pub name: String, #[serde(default)] pub parent: Option, }