Changed nutritional to nutrition.

This commit is contained in:
matthias committed 2026-09-28 01:55:09 +02:00
1 parent 7986632dab
commit 3ae697d852
15 files changed
+93 -10234

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="SqlDialectMappings">
<file url="file://$PROJECT_DIR$/server/migrations/20260926175212_add_nutrition.sql" dialect="GenericSQL" />
</component>
</project>
+8 -8
View File
@@ -5,7 +5,7 @@ use crate::models::variant::{load_article_variants, Variant};
use sqlx::{Arguments, Pool, Row, Postgres, Error, AssertSqlSafe}; use sqlx::{Arguments, Pool, Row, Postgres, Error, AssertSqlSafe};
use sqlx::postgres::{PgArguments, PgQueryResult, PgRow}; use sqlx::postgres::{PgArguments, PgQueryResult, PgRow};
use log::{debug, error, info}; use log::{debug, error, info};
use crate::models::nutritional::{load_nutritional, Nutritional}; use crate::models::nutrition::{load_nutrition, Nutrition};
use crate::models::unit::Unit; use crate::models::unit::Unit;
#[derive(Debug, Deserialize, Serialize, Clone, FromRow)] #[derive(Debug, Deserialize, Serialize, Clone, FromRow)]
@@ -24,7 +24,7 @@ pub struct Article {
pub bio_info: Option<String>, pub bio_info: Option<String>,
pub topm_id: Option<String>, pub topm_id: Option<String>,
pub additional_name: Option<String>, pub additional_name: Option<String>,
pub nutritional: Option<Nutritional>, pub nutrition: Option<Nutrition>,
} }
fn from_postgres_row_small(row: PgRow) -> Article { fn from_postgres_row_small(row: PgRow) -> Article {
@@ -43,7 +43,7 @@ fn from_postgres_row_small(row: PgRow) -> Article {
bio_info: row.get(10), bio_info: row.get(10),
topm_id: row.get(11), topm_id: row.get(11),
additional_name: row.get(12), additional_name: row.get(12),
nutritional: None, nutrition: None,
} }
} }
@@ -61,10 +61,10 @@ async fn from_postgres_row(row: PgRow, pool: PgPool) -> Article {
} }
}; };
let nutritional_id_option: Option<i64> = row.get(13); let nutrition_id_option: Option<i64> = row.get(13);
let nutritional: Option<Nutritional> = match nutritional_id_option { let nutrition: Option<Nutrition> = match nutrition_id_option {
Some(nutritional_id) => { Some(nutrition_id) => {
load_nutritional(nutritional_id, &pool).await load_nutrition(nutrition_id, &pool).await
} }
None => { None => {
None None
@@ -86,7 +86,7 @@ async fn from_postgres_row(row: PgRow, pool: PgPool) -> Article {
bio_info: row.get(10), bio_info: row.get(10),
topm_id: row.get(11), topm_id: row.get(11),
additional_name: row.get(12), additional_name: row.get(12),
nutritional: nutritional, nutrition: nutrition,
} }
} }
+1 -1
View File
@@ -5,4 +5,4 @@ pub mod unit;
pub mod label; pub mod label;
pub mod settings; pub mod settings;
pub mod supplier; pub mod supplier;
pub mod nutritional; pub mod nutrition;
@@ -6,7 +6,7 @@ use crate::models::article::Article;
use crate::models::variant::load_article_variants; use crate::models::variant::load_article_variants;
#[derive(Debug, Deserialize, Serialize, FromRow, Clone)] #[derive(Debug, Deserialize, Serialize, FromRow, Clone)]
pub struct Nutritional { pub struct Nutrition {
pub id: i64, pub id: i64,
pub calorific_value_kj: f64, pub calorific_value_kj: f64,
pub calorific_value_kcal: f64, pub calorific_value_kcal: f64,
@@ -19,7 +19,7 @@ pub struct Nutritional {
pub salt: f64, pub salt: f64,
} }
impl Default for Nutritional { impl Default for Nutrition {
fn default() -> Self { fn default() -> Self {
Self { Self {
id: 0, id: 0,
@@ -36,8 +36,8 @@ impl Default for Nutritional {
} }
} }
async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Nutritional { async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Nutrition {
Nutritional { Nutrition {
id: row.get(0), id: row.get(0),
calorific_value_kj: row.get(1), calorific_value_kj: row.get(1),
calorific_value_kcal: row.get(2), calorific_value_kcal: row.get(2),
@@ -51,14 +51,14 @@ async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Nutritional {
} }
} }
pub async fn load_nutritional(nutritional_id: i64, pool: &PgPool) -> Option<Nutritional> { pub async fn load_nutrition(nutrition_id: i64, pool: &PgPool) -> Option<Nutrition> {
let statement = format!( let statement = format!(
"SELECT * FROM {} WHERE id = $1", "SELECT * FROM {} WHERE id = $1",
"nutritional" "nutrition"
); );
let mut args = PgArguments::default(); let mut args = PgArguments::default();
args.add(nutritional_id); args.add(nutrition_id);
let res = sqlx::query_with( let res = sqlx::query_with(
AssertSqlSafe(statement.as_str()), args) AssertSqlSafe(statement.as_str()), args)
@@ -71,27 +71,27 @@ pub async fn load_nutritional(nutritional_id: i64, pool: &PgPool) -> Option<Nutr
Some(article) Some(article)
} }
Err(err) => { Err(err) => {
error!("Error while loading nutritional value: ID: {}", nutritional_id); error!("Error while loading nutrition value: ID: {}", nutrition_id);
None None
} }
} }
} }
pub async fn insert_nutritional(nutritional: &Nutritional, pool: PgPool) -> Option<Nutritional> { pub async fn insert_nutrition(nutrition: &Nutrition, pool: PgPool) -> Option<Nutrition> {
let mut args = PgArguments::default(); let mut args = PgArguments::default();
args.add(&nutritional.calorific_value_kj); args.add(&nutrition.calorific_value_kj);
args.add(&nutritional.calorific_value_kcal); args.add(&nutrition.calorific_value_kcal);
args.add(&nutritional.fat); args.add(&nutrition.fat);
args.add(&nutritional.saturated_fat); args.add(&nutrition.saturated_fat);
args.add(&nutritional.carbohydrates); args.add(&nutrition.carbohydrates);
args.add(&nutritional.sugar); args.add(&nutrition.sugar);
args.add(&nutritional.fibers); args.add(&nutrition.fibers);
args.add(&nutritional.protein); args.add(&nutrition.protein);
args.add(&nutritional.salt); args.add(&nutrition.salt);
let statement = format!( let statement = format!(
"INSERT INTO {} (calorific_value_kj, calorific_value_kcal, fat, carbohydrates, sugar, default_unit_id, fibers, protein, salt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *", "INSERT INTO {} (calorific_value_kj, calorific_value_kcal, fat, carbohydrates, sugar, default_unit_id, fibers, protein, salt) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *",
"nutritional", "nutrition",
); );
let res = sqlx::query_with( let res = sqlx::query_with(
@@ -103,33 +103,33 @@ pub async fn insert_nutritional(nutritional: &Nutritional, pool: PgPool) -> Opti
match res { match res {
Ok(record) => { Ok(record) => {
let nutritional = from_postgres_row(record, &pool).await; let nutrition = from_postgres_row(record, &pool).await;
Some(nutritional) Some(nutrition)
} }
Err(err) => { Err(err) => {
error!("Error while loading newly created nutritional values. ID: {}", nutritional.id); error!("Error while loading newly created nutrition values. ID: {}", nutrition.id);
None None
} }
} }
} }
pub async fn update_nutritional(nutritional: &Nutritional, pool: PgPool) -> Option<Nutritional> { pub async fn update_nutrition(nutrition: &Nutrition, pool: PgPool) -> Option<Nutrition> {
let mut args = PgArguments::default(); let mut args = PgArguments::default();
args.add(&nutritional.id); args.add(&nutrition.id);
args.add(&nutritional.calorific_value_kj); args.add(&nutrition.calorific_value_kj);
args.add(&nutritional.calorific_value_kcal); args.add(&nutrition.calorific_value_kcal);
args.add(&nutritional.fat); args.add(&nutrition.fat);
args.add(&nutritional.saturated_fat); args.add(&nutrition.saturated_fat);
args.add(&nutritional.carbohydrates); args.add(&nutrition.carbohydrates);
args.add(&nutritional.sugar); args.add(&nutrition.sugar);
args.add(&nutritional.fibers); args.add(&nutrition.fibers);
args.add(&nutritional.protein); args.add(&nutrition.protein);
args.add(&nutritional.salt); args.add(&nutrition.salt);
let statement = format!( let statement = format!(
"UPDATE {} SET calorific_value_kj = $3, calorific_value_kcal = $4, fat = $5,\ "UPDATE {} SET calorific_value_kj = $3, calorific_value_kcal = $4, fat = $5,\
saturated_fat = $6, carbohydrates = $7, sugar = $8, fibers = $9, protein = $10, salt = $11 WHERE id = $1 RETURNING *", saturated_fat = $6, carbohydrates = $7, sugar = $8, fibers = $9, protein = $10, salt = $11 WHERE id = $1 RETURNING *",
"nutritional", "nutrition",
); );
let res = sqlx::query_with( let res = sqlx::query_with(
@@ -145,17 +145,17 @@ pub async fn update_nutritional(nutritional: &Nutritional, pool: PgPool) -> Opti
Some(updated) Some(updated)
} }
Err(err) => { Err(err) => {
error!("Error while updating nutritional values. ID {}", nutritional.id); error!("Error while updating nutrition values. ID {}", nutrition.id);
None None
} }
} }
} }
pub async fn delete_nutritional(nutritional_id: i64, pool: PgPool) -> Option<()> { pub async fn delete_nutrition(nutrition_id: i64, pool: PgPool) -> Option<()> {
let result = sqlx::query( let result = sqlx::query(
AssertSqlSafe(format!("DELETE FROM {} WHERE id = {}", AssertSqlSafe(format!("DELETE FROM {} WHERE id = {}",
"nutritional", "nutrition",
nutritional_id nutrition_id
).as_str()) ).as_str())
).execute(&pool).await; ).execute(&pool).await;
@@ -164,8 +164,7 @@ pub async fn delete_nutritional(nutritional_id: i64, pool: PgPool) -> Option<()>
Some(()) Some(())
} }
Err(err) => { Err(err) => {
println!("Error deleting nutritional. ID: {:#?}", err); println!("Error deleting nutrition. ID: {:#?}", err);
None None
} }
} }
+10 -10
View File
@@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
use sqlx::{Arguments, AssertSqlSafe, FromRow, PgPool, Row}; use sqlx::{Arguments, AssertSqlSafe, FromRow, PgPool, Row};
use sqlx::postgres::{PgArguments, PgRow}; use sqlx::postgres::{PgArguments, PgRow};
use crate::models::label::{load_label, Label}; use crate::models::label::{load_label, Label};
use crate::models::nutritional::{load_nutritional, Nutritional}; use crate::models::nutrition::{load_nutrition, Nutrition};
use crate::models::unit::Unit; use crate::models::unit::Unit;
#[derive(Debug, Deserialize, Serialize, Clone, FromRow)] #[derive(Debug, Deserialize, Serialize, Clone, FromRow)]
@@ -18,7 +18,7 @@ pub struct Variant {
pub label: Option<Label>, pub label: Option<Label>,
pub variant_description: Option<String>, pub variant_description: Option<String>,
pub topm_row: Option<String>, pub topm_row: Option<String>,
pub nutritional: Option<Nutritional>, pub nutrition: Option<Nutrition>,
} }
async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant { async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant {
@@ -32,10 +32,10 @@ async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant {
} }
}; };
let nutritional_id_option: Option<i64> = row.get(11); let nutrition_id_option: Option<i64> = row.get(11);
let nutritional: Option<Nutritional> = match nutritional_id_option { let nutrition: Option<Nutrition> = match nutrition_id_option {
Some(nutritional_id) => { Some(nutrition_id) => {
load_nutritional(nutritional_id, &pool).await load_nutrition(nutrition_id, &pool).await
} }
None => { None => {
None None
@@ -53,7 +53,7 @@ async fn from_postgres_row(row: PgRow, pool: &PgPool) -> Variant {
label: label, label: label,
variant_description: row.get(9), variant_description: row.get(9),
topm_row: row.get(10), topm_row: row.get(10),
nutritional: nutritional, nutrition: nutrition,
} }
} }
@@ -99,7 +99,7 @@ pub async fn insert_variant(article_id: i64, variant: &Variant, pool: PgPool) ->
} }
}; };
let nutritional_id = match &variant.nutritional { let nutrition_id = match &variant.nutrition {
Some(label) => { Some(label) => {
Some(label.id) Some(label.id)
} }
@@ -119,11 +119,11 @@ pub async fn insert_variant(article_id: i64, variant: &Variant, pool: PgPool) ->
args.add(label_id); args.add(label_id);
args.add(&variant.variant_description); args.add(&variant.variant_description);
args.add(&variant.topm_row); args.add(&variant.topm_row);
args.add(nutritional_id); args.add(nutrition_id);
let statement = format!( let statement = format!(
"INSERT INTO {} (article_id, weight, ean, name, description, ingredients, unit_id, label_id, \ "INSERT INTO {} (article_id, weight, ean, name, description, ingredients, unit_id, label_id, \
variant_description, topm_row, nutritional_id) \ variant_description, topm_row, nutrition_id) \
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *", VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11) RETURNING *",
"variant", "variant",
); );
+1 -1
View File
@@ -96,7 +96,7 @@
<v-divider vertical/> <v-divider vertical/>
<Nutrition v-bind:nutrition="store.article.nutritional"/> <Nutrition v-bind:nutrition="store.article.nutrition"/>
<v-btn <v-btn
:flat="true" :flat="true"
@@ -2,10 +2,10 @@
import {useLabelEditorStore} from "~/store/labelEditorStore"; import {useLabelEditorStore} from "~/store/labelEditorStore";
import type {Ref} from "vue"; import type {Ref} from "vue";
import DeleteConfirm from "~/components/ui/deleteConfirm.vue"; import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
import type {Nutritional} from "~/types/nutritional.ts"; import type {Nutrition} from "~/types/nutrition.ts";
const props = defineProps({ const props = defineProps({
nutrition: {type: Object as PropType<Nutritional | null>, required: true}, nutrition: {type: Object as PropType<Nutrition | null>, required: true},
}); });
let store = useLabelEditorStore(); let store = useLabelEditorStore();
@@ -4,7 +4,7 @@
import { Variant } from "~/types/variant"; import { Variant } from "~/types/variant";
import type {Unit} from "~/types/unit"; import type {Unit} from "~/types/unit";
import type {Label} from "~/types/label"; import type {Label} from "~/types/label";
import type {Nutritional} from "~/types/nutritional.ts"; import type {Nutrition} from "~/types/nutrition.ts";
let store = useLabelEditorStore(); let store = useLabelEditorStore();
@@ -5,7 +5,7 @@
import DeleteConfirm from "~/components/ui/deleteConfirm.vue"; import DeleteConfirm from "~/components/ui/deleteConfirm.vue";
import type {Unit} from "~/types/unit"; import type {Unit} from "~/types/unit";
import type {Label} from "~/types/label"; import type {Label} from "~/types/label";
import type {Nutritional} from "~/types/nutritional.ts"; import type {Nutrition} from "~/types/nutrition.ts";
let store = useLabelEditorStore(); let store = useLabelEditorStore();
@@ -24,7 +24,7 @@
let label: Ref<Label | null> = ref<Label | null>(JSON.parse(JSON.stringify(props.variant.label))); let label: Ref<Label | null> = ref<Label | null>(JSON.parse(JSON.stringify(props.variant.label)));
let variant_description: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.variant_description))); let variant_description: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.variant_description)));
let topm_row: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.topm_row))); let topm_row: Ref<string | null> = ref<string | null>(JSON.parse(JSON.stringify(props.variant.topm_row)));
let nutrition: Ref<Nutritional | null> = ref<Nutritional | null>(JSON.parse(JSON.stringify(props.variant.nutritional))); let nutrition: Ref<Nutrition | null> = ref<Nutrition | null>(JSON.parse(JSON.stringify(props.variant.nutrition)));
function toggleEdit() { function toggleEdit() {
if (edit.value) { if (edit.value) {
+4 -4
View File
@@ -1,7 +1,7 @@
import type {Variant} from "~/types/variant"; import type {Variant} from "~/types/variant";
import type {Origin} from "~/types/origin"; import type {Origin} from "~/types/origin";
import type {Unit} from "~/types/unit"; import type {Unit} from "~/types/unit";
import type {Nutritional} from "~/types/nutritional.ts"; import type {Nutrition} from "~/types/nutrition.ts";
export class Article { export class Article {
readonly id: number; readonly id: number;
@@ -18,13 +18,13 @@ export class Article {
bio_info: string | null; bio_info: string | null;
topm_id: string | null; topm_id: string | null;
additional_name: string | null; additional_name: string | null;
nutritional: Nutritional | null; nutrition: Nutrition | null;
constructor(id: number, name: string, bio: boolean, origin: Origin, description: string | null, constructor(id: number, name: string, bio: boolean, origin: Origin, description: string | null,
ingredients: string | null, default_unit: Unit, variants: Array<Variant> | null, ingredients: string | null, default_unit: Unit, variants: Array<Variant> | null,
mhd: string | null, bio_origin: string | null, allergens_text: string | null, mhd: string | null, bio_origin: string | null, allergens_text: string | null,
bio_info: string | null, topm_id: string | null, additional_name: string | null, bio_info: string | null, topm_id: string | null, additional_name: string | null,
nutritional: Nutritional | null) { nutrition: Nutrition | null) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.bio = bio; this.bio = bio;
@@ -45,6 +45,6 @@ export class Article {
this.bio_info = bio_info; this.bio_info = bio_info;
this.topm_id = topm_id; this.topm_id = topm_id;
this.additional_name = additional_name; this.additional_name = additional_name;
this.nutritional = nutritional; this.nutrition = nutrition;
} }
} }
@@ -1,4 +1,4 @@
export class Nutritional { export class Nutrition {
id: number; id: number;
calorific_value_kj: number; calorific_value_kj: number;
calorific_value_kcal: number; calorific_value_kcal: number;
+4 -4
View File
@@ -1,6 +1,6 @@
import type {Unit} from "~/types/unit"; import type {Unit} from "~/types/unit";
import type {Label} from "~/types/label"; import type {Label} from "~/types/label";
import type {Nutritional} from "~/types/nutritional.ts"; import type {Nutrition} from "~/types/nutrition.ts";
export class Variant { export class Variant {
readonly id: number; readonly id: number;
@@ -13,12 +13,12 @@ export class Variant {
label: Label | null; label: Label | null;
variant_description: string | null; variant_description: string | null;
topm_row: string | null; topm_row: string | null;
nutritional: Nutritional | null; nutrition: Nutrition | null;
constructor(id: number, weight: string, ean: string|null, name: string|null, constructor(id: number, weight: string, ean: string|null, name: string|null,
description:string|null, ingredients: string|null, unit: Unit, description:string|null, ingredients: string|null, unit: Unit,
label: Label | null, variant_description: string | null, topm_row: string | null, label: Label | null, variant_description: string | null, topm_row: string | null,
nutritional: Nutritional | null) { nutrition: Nutrition | null) {
this.id = id; this.id = id;
this.weight = weight; this.weight = weight;
this.ean = ean; this.ean = ean;
@@ -29,6 +29,6 @@ export class Variant {
this.label = label; this.label = label;
this.variant_description = variant_description; this.variant_description = variant_description;
this.topm_row = topm_row; this.topm_row = topm_row;
this.nutritional = nutritional; this.nutrition = nutrition;
} }
} }
-10146
View File
File diff suppressed because it is too large. Load diff
@@ -1,5 +1,5 @@
-- Add migration script here -- Add migration script here
CREATE TABLE nutritional CREATE TABLE nutrition
( (
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 ) Unique, id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 ) Unique,
calorific_value_kj double precision DEFAULT 0 NOT NULL, calorific_value_kj double precision DEFAULT 0 NOT NULL,
@@ -14,15 +14,15 @@ CREATE TABLE nutritional
); );
ALTER TABLE public.article ALTER TABLE public.article
ADD nutritional_id bigint, ADD nutrition_id bigint,
ADD CONSTRAINT article_nutritional_id_fkey ADD CONSTRAINT article_nutrition_id_fkey
foreign key (nutritional_id) foreign key (nutrition_id)
references nutritional(id) references nutrition(id)
ON DELETE NO ACTION; ON DELETE NO ACTION;
ALTER TABLE public.variant ALTER TABLE public.variant
ADD nutritional_id bigint, ADD nutrition_id bigint,
ADD CONSTRAINT variant_nutritional_id_fkey ADD CONSTRAINT variant_nutrition_id_fkey
foreign key (nutritional_id) foreign key (nutrition_id)
references nutritional(id) references nutrition(id)
ON DELETE NO ACTION; ON DELETE NO ACTION;
+5 -5
View File
@@ -125,7 +125,7 @@ async fn get_article(
bio_info: None, bio_info: None,
topm_id: None, topm_id: None,
additional_name: None, additional_name: None,
nutritional: None, nutrition: None,
}; };
(StatusCode::INTERNAL_SERVER_ERROR, Json(article)) (StatusCode::INTERNAL_SERVER_ERROR, Json(article))
@@ -160,7 +160,7 @@ async fn create_article(
bio_info: None, bio_info: None,
topm_id: None, topm_id: None,
additional_name: None, additional_name: None,
nutritional: None, nutrition: None,
}; };
(StatusCode::INTERNAL_SERVER_ERROR, Json(article)) (StatusCode::INTERNAL_SERVER_ERROR, Json(article))
@@ -197,7 +197,7 @@ async fn update_article_route(
bio_info: None, bio_info: None,
topm_id: None, topm_id: None,
additional_name: None, additional_name: None,
nutritional: None, nutrition: None,
}; };
(StatusCode::INTERNAL_SERVER_ERROR, Json(article)) (StatusCode::INTERNAL_SERVER_ERROR, Json(article))
@@ -249,7 +249,7 @@ async fn add_variant(
label: None, label: None,
variant_description: None, variant_description: None,
topm_row: None, topm_row: None,
nutritional: None, nutrition: None,
}; };
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant)) (StatusCode::INTERNAL_SERVER_ERROR, Json(variant))
@@ -282,7 +282,7 @@ async fn update_variant_route(
label: None, label: None,
variant_description: None, variant_description: None,
topm_row: None, topm_row: None,
nutritional: None, nutrition: None,
}; };
(StatusCode::INTERNAL_SERVER_ERROR, Json(variant)) (StatusCode::INTERNAL_SERVER_ERROR, Json(variant))