Added unit to db and structs/types.

This commit is contained in:
2026-01-26 22:09:32 +01:00
parent 7879f69255
commit 8a27639aad
14 changed files with 243 additions and 60 deletions
+35
View File
@@ -0,0 +1,35 @@
-- Add migration script here
CREATE TABLE unit
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 0 MINVALUE 0 ),
name text NOT NULL,
display text NOT NULL,
CONSTRAINT unit_id PRIMARY KEY (id)
INCLUDE(id)
);
-- Insert units
INSERT INTO unit (name, display) VALUES ('KG', 'kg');
INSERT INTO unit (name, display) VALUES ('G', 'g');
INSERT INTO unit (name, display) VALUES ('L', 'l');
INSERT INTO unit (name, display) VALUES ('ML', 'ml');
INSERT INTO unit (name, display) VALUES ('Stk', 'Stk');
-- Alter article and variant table to add unit
ALTER TABLE public.variant
ADD unit_id bigint NOT NULL DEFAULT 1,
ADD CONSTRAINT variant_unit_id_fkey
foreign key (unit_id)
references unit(id)
ON DELETE NO ACTION;
ALTER TABLE public.article
ADD default_unit_id bigint NOT NULL DEFAULT 1,
ADD CONSTRAINT article_unit_id_fkey
foreign key (default_unit_id)
references unit(id)
ON DELETE NO ACTION;
-- Add display text to origin table
ALTER TABLE public.origin
ADD display text NOT NULL DEFAULT 'NOT SET';
+6
View File
@@ -16,6 +16,7 @@ use tower_http::cors::{AllowOrigin, Any, CorsLayer};
use tracing::info;
use http::header::{AUTHORIZATION, ACCEPT, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, ACCESS_CONTROL_ALLOW_CREDENTIALS};
use common::models::article;
use common::models::unit::Unit;
use common::models::variant::{delete_variant, insert_variant, update_variant, Variant};
#[tokio::main]
@@ -102,6 +103,7 @@ async fn get_article(
origin: Origin::EU,
description: None,
ingredients: None,
default_unit: Unit::G,
variants: vec![],
};
@@ -129,6 +131,7 @@ async fn create_article(
origin: Origin::EU,
description: None,
ingredients: None,
default_unit: Unit::G,
variants: vec![],
};
@@ -158,6 +161,7 @@ async fn update_article_route(
origin: Origin::EU,
description: None,
ingredients: None,
default_unit: Unit::G,
variants: vec![],
};
@@ -206,6 +210,7 @@ async fn add_variant(
name: None,
description: None,
ingredients: None,
unit: Unit::G,
};
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant))
@@ -234,6 +239,7 @@ async fn update_variant_route(
name: None,
description: None,
ingredients: None,
unit: Unit::G,
};
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant))