// rocie - An enterprise grocery management system // // Copyright (C) 2026 Benedikt Peetz // SPDX-License-Identifier: GPL-3.0-or-later // // This file is part of Rocie. // // You should have received a copy of the License along with this program. // If not, see . use crate::{ app::App, storage::sql::{insert::Operations, unit::Unit, unit_property::UnitProperty}, }; #[expect(clippy::unnecessary_wraps, reason = "The API expects an Option<_>")] fn so(input: &'static str) -> Option { Some(s(input)) } fn s(input: &'static str) -> String { String::from(input) } macro_rules! register { ( $app:ident # $unit_prop_description:literal, $unit_prop_name:literal $( -> $unit_full_name_singular:ident, $unit_full_name_plural:ident, $unit_short_name:ident )* ) => { let mut ops = Operations::new(concat!( "create", $unit_prop_name, "unit property (during provisioning)" )); let unit_property = UnitProperty::register( s($unit_prop_name), so($unit_prop_description), &mut ops, ) .id; ops.apply(&$app).await?; let mut ops = Operations::new(concat!( "create default units for", $unit_prop_name, "property (during provisioning)" )); $( Unit::register( s(stringify!($unit_full_name_singular)), s(stringify!($unit_full_name_plural)), s(stringify!($unit_short_name)), None, unit_property, &mut ops, ); )* ops.apply(&$app).await?; }; } pub(super) async fn add_defaults_0_to_1(app: &App) -> Result<(), apply_defaults::Error> { register!( app # "Time mesurement units", "Time" -> second, seconds, s -> minute, minutes, min -> hour, hours, h ); register!( app # "Mass (weight) mesurement units", "Mass" -> milligram, milligrams, mg -> gram, grams, g -> kilogram, kilograms, kg ); register!( app # "Volume mesurement units", "Volume" -> milliliter, millilters, ml -> deciliter, deciliters, dl -> liter, liters, l // English -> tablespoon, tablespoons, tbsp -> teaspoon, teaspoons, tsp // Swedish -> tesked, teskedar, tsk -> matsked, matskedar, msk ); Ok(()) } pub(crate) mod apply_defaults { use crate::storage::sql::insert::{self, apply}; #[derive(thiserror::Error, Debug)] pub(crate) enum Error { #[error("Failed to add new default unit-property the database: {0}")] AddUnitProperty(#[from] apply::Error), #[error("Failed to add new default unit the database: {0}")] AddUnit(#[from] apply::Error), } }