Compare commits

...
9 Commits
Author SHA1 Message Date
matthias eec69819e9 Updated sql statment for bartender. 2026-10-10 17:01:32 +02:00
matthias 8998752865 Updated dependencies. 2026-10-10 14:18:35 +02:00
matthias fc349a418b Updated bartender files. 2026-10-05 04:46:58 +02:00
matthias 058deacd32 Updated bartender files. 2026-10-05 04:46:14 +02:00
matthias 6980a2acc0 Added bartender files for Käfer Essen im Glas. 2026-09-30 21:29:36 +02:00
matthias 0d7770a446 Updated versions numbers. 2026-09-30 19:52:33 +02:00
matthias c53d842c34 Added missing functionality. 2026-09-29 02:45:32 +02:00
matthias d613f8c1d7 Started adding nutrition editing logic. 2026-09-28 03:46:36 +02:00
matthias 3ae697d852 Changed nutritional to nutrition. 2026-09-28 01:55:09 +02:00
26 changed files with 519 additions and 10257 deletions

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>
Generated
+5 -5
View File
@@ -395,7 +395,7 @@ checksum = "b05b61dc5112cbb17e4b6cd61790d9845d13888356391624cbe7e41efeac1e75"
[[package]] [[package]]
name = "common" name = "common"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"log", "log",
"serde", "serde",
@@ -1144,7 +1144,7 @@ dependencies = [
[[package]] [[package]]
name = "label_editor" name = "label_editor"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"common", "common",
"server", "server",
@@ -1573,7 +1573,7 @@ dependencies = [
[[package]] [[package]]
name = "server" name = "server"
version = "0.3.0" version = "0.4.0"
dependencies = [ dependencies = [
"axum", "axum",
"common", "common",
@@ -1969,9 +1969,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20"
[[package]] [[package]]
name = "tokio" name = "tokio"
version = "1.53.1" version = "1.53.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "202caea871b69668250d242070849eb495be178ed697a3e98aebce5bc81a0bed" checksum = "e95f91fcc7a621e8b030f6aa23c71fe9838ae2fb4d8118b75602a328f5144044"
dependencies = [ dependencies = [
"bytes", "bytes",
"libc", "libc",
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "label_editor" name = "label_editor"
version = "0.3.0" version = "0.4.0"
edition = "2024" edition = "2024"
authors = ["Matthias Lodner <matthias@lodner.de>"] authors = ["Matthias Lodner <matthias@lodner.de>"]
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+56
View File
@@ -92,3 +92,59 @@ ORDER BY a.name, v.weight ASC
## Lodner kleines Etikett ## Lodner kleines Etikett
## Käfer Essen im Glas
### SQL Abfrage
```sql
SELECT
a.name AS product,
CONCAT(a.topm_id, v.topm_row) AS aritcle_number,
COALESCE(v.name, a.name) AS name,
COALESCE(a.additional_name, COALESCE(v.name, a.name)) AS sigel_name,
CONCAT(CONCAT(v.weight, ' '), u.display) AS weight,
v.ean AS ean,
COALESCE(v.description, a.description) AS description,
COALESCE(v.ingredients, a.ingredients) AS ingredients,
COALESCE(a.mhd, s.mhd) AS mhd,
COALESCE(a.allergens_text, s.allergens_text) AS allergens_info,
CONCAT(
CONCAT(n.calorific_value_kj, ' kJ<br>'),
CONCAT(n.calorific_value_kcal, ' kcal')
) AS energy,
n.fat,
n.saturated_fat,
n.carbohydrates,
n.sugar,
n.fibers,
n.protein,
n.salt
FROM article AS a
INNER JOIN variant AS v ON v.article_id = a.id
INNER JOIN settings AS s ON v.article_id = v.article_id
INNER JOIN unit AS u ON v.unit_id = u.id
INNER JOIN label AS l ON v.label_id = l.id
INNER JOIN nutrition AS n ON n.id = a.nutrition_id
WHERE v.label_id = 3
ORDER BY a.name, v.weight ASC
```
### HTML settings for label
#### Product title
```html
<div style="text-align: center; font-size: 16pt; font-family: Optima LT Std;">
</div><div style="text-align: center; font-size: 8pt; font-family: Optima nova LT Pro Titling Init;">- HANDGEMACHT -</div>
```
#### MHD
```html
<div style="text-align: center; font-size: 7pt; font-family: Optima LT Std;">Ungeöffnet bei 4°C - 7°C mindestens haltbar bis:
</div>
```
#### Impressum
```html
<div style="text-align: center; font-size: 7pt; font-family: Optima LT Std;">
</div>
```
+1 -1
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "common" name = "common"
version = "0.3.0" version = "0.4.0"
edition = "2024" edition = "2024"
authors = ["Matthias Lodner <matthias@lodner.de>"] authors = ["Matthias Lodner <matthias@lodner.de>"]
+71 -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, insert_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,29 @@ 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>,
}
impl Default for Article {
fn default() -> Self {
Self {
id: 0,
name: "".to_string(),
bio: false,
origin: Origin::EU,
description: None,
ingredients: None,
default_unit: Unit::G,
variants: vec![],
mhd: None,
bio_origin: None,
allergens_text: None,
bio_info: None,
topm_id: None,
additional_name: None,
nutrition: None,
}
}
} }
fn from_postgres_row_small(row: PgRow) -> Article { fn from_postgres_row_small(row: PgRow) -> Article {
@@ -43,7 +65,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 +83,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 +108,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,
} }
} }
@@ -244,3 +266,44 @@ pub async fn delete_article(article_id: i64, pool: PgPool) -> Option<()> {
} }
} }
} }
pub async fn article_add_nutrition(article_id: i64, pool: PgPool) -> Option<Article> {
let nutrition = insert_nutrition(&Nutrition::default(), &pool).await;
match nutrition {
Some(nutrition) => {
let mut args = PgArguments::default();
args.add(&article_id);
args.add(&nutrition.id);
let statement = format!(
"UPDATE {} SET nutrition_id = $2 WHERE id = $1 RETURNING *",
"article",
);
let res = sqlx::query_with(
AssertSqlSafe(statement.as_str()),
args)
.fetch_one(&pool).await;
info!("{:#?}", res);
match res {
Ok(record) => {
match load_article(article_id, pool).await {
Some(article) => Some(article),
None => None
}
}
Err(err) => {
error!("Error while adding nutrition to article: {}", article_id);
None
}
}
},
None => {
error!("Error while creating nutrition");
None
}
}
}
+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,65 +71,68 @@ 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, saturated_fat,\
"nutritional", carbohydrates, sugar, fibers, protein, salt)\
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9) RETURNING *",
"nutrition",
); );
let res = sqlx::query_with( let res = sqlx::query_with(
AssertSqlSafe(statement.as_str()), AssertSqlSafe(statement.as_str()),
args) args)
.fetch_one(&pool).await; .fetch_one(pool).await;
info!("{:#?}", res); info!("{:#?}", res);
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_id: i64, 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 = $2, calorific_value_kcal = $3, fat = $4,\
saturated_fat = $6, carbohydrates = $7, sugar = $8, fibers = $9, protein = $10, salt = $11 WHERE id = $1 RETURNING *", saturated_fat = $5, carbohydrates = $6, sugar = $7, fibers = $8, protein = $9,\
"nutritional", salt = $10 WHERE id = $1 RETURNING *",
"nutrition",
); );
let res = sqlx::query_with( let res = sqlx::query_with(
@@ -145,17 +148,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 +167,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",
); );
+3 -1
View File
@@ -96,7 +96,9 @@
<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"
+168 -6
View File
@@ -2,21 +2,80 @@
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 {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();
let loading: Ref<boolean> = ref<boolean>(false); let loading: Ref<boolean> = ref<boolean>(false);
let dialog: Ref<boolean> = ref<boolean>(false); let dialog: Ref<boolean> = ref<boolean>(false);
async function updateNutrition() { let calorific_value_kj: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let calorific_value_kcal: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let fat: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let saturated_fat: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let carbohydrates: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let sugar: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let fibers: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let protein: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
let salt: Ref<number> = ref<number>(JSON.parse(JSON.stringify(0)));
watch(dialog, async (oldDialog) => {
if (oldDialog) {
if (props.nutrition != null) {
calorific_value_kj.value = props.nutrition.calorific_value_kj;
calorific_value_kcal.value = props.nutrition.calorific_value_kcal;
fat.value = props.nutrition.fat;
saturated_fat.value = props.nutrition.saturated_fat;
carbohydrates.value = props.nutrition.carbohydrates;
sugar.value = props.nutrition.sugar;
fibers.value = props.nutrition.fibers;
protein.value = props.nutrition.protein;
salt.value = props.nutrition.salt;
}
}
})
async function createNutrition() {
if (store.article != null) {
await store.createArticleNutrition(store.article.id);
calorific_value_kj.value = 0;
calorific_value_kcal.value = 0;
fat.value = 0;
saturated_fat.value = 0;
carbohydrates.value = 0;
sugar.value = 0;
fibers.value = 0;
protein.value = 0;
salt.value = 0;
}
}
async function updateNutrition() {
if (props.nutrition != null) {
let nutrition = new Nutrition(props.nutrition.id,
parseFloat(calorific_value_kj.value.toString()),
parseFloat(calorific_value_kcal.value.toString()),
parseFloat(fat.value.toString()),
parseFloat(saturated_fat.value.toString()),
parseFloat(carbohydrates.value.toString()),
parseFloat(sugar.value.toString()),
parseFloat(fibers.value.toString()),
parseFloat(protein.value.toString()),
parseFloat(salt.value.toString()),
);
await store.updateNutrition(nutrition);
}
} }
async function deleteNutrition() { async function deleteNutrition() {
if (props.nutrition != null) {
await store.deleteArticleNutrition(props.nutrition);
}
closeDialog(); closeDialog();
} }
@@ -75,16 +134,119 @@
<v-divider/> <v-divider/>
<v-card-text> <v-card-text>
test
<div v-if="props.nutrition != null">
<v-row>
<v-col>
<v-text-field
v-model="calorific_value_kcal"
:disabled="loading"
hint="Brennwert in kcal"
label="Brennwert"
suffix="kcal"
type="number"
></v-text-field>
</v-col>
<v-col>
<v-text-field
v-model="calorific_value_kj"
:disabled="loading"
hint="Brennwert in kj"
label="Brennwert"
suffix="kj"
type="number"
></v-text-field>
</v-col>
</v-row>
<v-text-field
v-model="fat"
:disabled="loading"
hint="Fett in g"
label="Fett"
suffix="g"
type="number"
></v-text-field>
<v-text-field
v-model="saturated_fat"
:disabled="loading"
hint="Gesättigte Fettsäuren in g"
label="Gesättigte Fettsäuren"
suffix="g"
type="number"
></v-text-field>
<v-text-field
v-model="carbohydrates"
:disabled="loading"
hint="Kohlenhydrate in g"
label="Kohlenhydrate"
suffix="g"
type="number"
></v-text-field>
<v-text-field
v-model="sugar"
:disabled="loading"
hint="Zucker in g"
label="Zucker"
suffix="g"
type="number"
></v-text-field>
<v-text-field
v-model="fibers"
:disabled="loading"
hint="Ballaststoffe in g"
label="Ballaststoffe"
suffix="g"
type="number"
></v-text-field>
<v-text-field
v-model="protein"
:disabled="loading"
hint="Eiweiß in g"
label="Eiweiß"
suffix="g"
type="number"
></v-text-field>
<v-text-field
v-model="salt"
:disabled="loading"
hint="Salz in g"
label="Salz"
suffix="g"
type="number"
></v-text-field>
</div>
<div v-else>
Keine Nährwerte hinterlegt
</div>
</v-card-text> </v-card-text>
<v-divider/> <v-divider/>
<v-card-actions> <v-card-actions>
<v-spacer/> <v-spacer/>
<v-btn
v-if="props.nutrition == null"
variant="text"
:disabled="loading"
@click="createNutrition()"
>
Hinzufügen
</v-btn>
<DeleteConfirm <DeleteConfirm
v-else
title="Nährwert löschen?" title="Nährwert löschen?"
:disable="!loading" :disable="loading"
@delete="deleteNutrition()" @delete="deleteNutrition()"
/> />
<v-divider vertical/> <v-divider vertical/>
@@ -92,7 +254,7 @@
<v-btn <v-btn
variant="text" variant="text"
:disabled="loading" :disabled="loading"
@click="closeDialog()" @click="updateNutrition()"
> >
Speichern Speichern
</v-btn> </v-btn>
@@ -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) {
+58 -1
View File
@@ -1,5 +1,5 @@
import {defineStore} from "pinia"; import {defineStore} from "pinia";
import type {Article} from "~/types/article"; import {Article} from "~/types/article";
import {NotificationMessage} from "~/types/notificationMessage"; import {NotificationMessage} from "~/types/notificationMessage";
import type {RuntimeConfig} from "nuxt/schema"; import type {RuntimeConfig} from "nuxt/schema";
import {Origin} from "~/types/origin"; import {Origin} from "~/types/origin";
@@ -8,6 +8,7 @@ import {Unit} from "~/types/unit";
import type {Label} from "~/types/label"; import type {Label} from "~/types/label";
import type {Settings} from "~/types/settings"; import type {Settings} from "~/types/settings";
import type {Supplier} from "~/types/supplier"; import type {Supplier} from "~/types/supplier";
import type {Nutrition} from "~/types/nutrition.ts";
interface State { interface State {
config: RuntimeConfig, config: RuntimeConfig,
@@ -455,5 +456,61 @@ export const useLabelEditorStore = defineStore('label_editor_store', {
this.addNotification(true, 'Fehler beim löschen des Lieferanten.'); this.addNotification(true, 'Fehler beim löschen des Lieferanten.');
} }
}, },
// Nutrition
async createArticleNutrition(articleID: number) {
try {
let article = await $fetch<Article>(this.config.public.url + '/article/' + articleID +'/nutrition', {
method: 'POST',
});
this.article = article;
this.addNotification(false, 'Nährwert angelegt');
} catch {
this.addNotification(true, 'Fehler beim anlegen der Nährwerte.');
}
},
async updateNutrition(nutrition: Nutrition): Promise<Nutrition> {
try {
let updatedNutrition = await $fetch<Nutrition>(this.config.public.url + '/nutrition/' + nutrition.id, {
method: 'POST',
body: JSON.stringify(nutrition),
});
this.addNotification(false, 'Nährwert aktualisiert.');
return updatedNutrition;
} catch {
this.addNotification(true, 'Fehler beim aktualisieren des Nährwerts.');
return nutrition;
}
},
async deleteArticleNutrition(nutrition: Nutrition): Promise<Nutrition | null> {
if (this.article != null) {
try {
await $fetch(this.config.public.url + '/article/' + this.article.id + '/nutrition', {
method: 'DELETE',
});
this.addNotification(false, 'Nährwert gelöscht.');
this.article.nutrition = null;
return null;
} catch {
this.addNotification(true, 'Fehler beim löschen des Nährwerts.');
return nutrition
}
} else {
return nutrition;
}
},
// ...
}, },
}); });
+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
+4 -3
View File
@@ -1,5 +1,6 @@
{ {
"name": "frontend", "name": "frontend",
"version": "0.4.0",
"type": "module", "type": "module",
"private": true, "private": true,
"scripts": { "scripts": {
@@ -13,14 +14,14 @@
"@fontsource/roboto": "5.3.0", "@fontsource/roboto": "5.3.0",
"@mdi/font": "7.4.47", "@mdi/font": "7.4.47",
"@pinia/nuxt": "1.0.2", "@pinia/nuxt": "1.0.2",
"nuxt": "4.5.2", "nuxt": "4.6.1",
"pinia": "4.0.3", "pinia": "4.0.3",
"vue": "3.5.43", "vue": "3.5.43",
"vue-router": "5.3.1", "vue-router": "5.4.0",
"vuetify-pro-tiptap": "3.0.0" "vuetify-pro-tiptap": "3.0.0"
}, },
"devDependencies": { "devDependencies": {
"vite-plugin-vuetify": "2.1.3", "vite-plugin-vuetify": "2.1.3",
"vuetify": "4.2.2" "vuetify": "4.2.4"
} }
} }
+2 -2
View File
@@ -1,6 +1,6 @@
[package] [package]
name = "server" name = "server"
version = "0.3.0" version = "0.4.0"
edition = "2024" edition = "2024"
authors = ["Matthias Lodner <matthias@lodner.de>"] authors = ["Matthias Lodner <matthias@lodner.de>"]
@@ -12,7 +12,7 @@ path = "src/main.rs"
common = {path = "../common"} common = {path = "../common"}
axum = "0.8.9" axum = "0.8.9"
tokio = { version = "1.53.1", default-features = false, features = ["full"] } tokio = { version = "1.53.2", default-features = false, features = ["full"] }
http = "1.5.0" http = "1.5.0"
tower-http = {version = "0.7.1", features = ["cors"]} tower-http = {version = "0.7.1", features = ["cors"]}
tracing = "=0.1.44" tracing = "=0.1.44"
@@ -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;
+66 -7
View File
@@ -9,14 +9,15 @@ use axum::routing::delete;
use dotenv::dotenv; use dotenv::dotenv;
use env_logger::fmt::style::Reset; use env_logger::fmt::style::Reset;
use http::{header, Method}; use http::{header, Method};
use common::models::article::{delete_article, insert_article, load_article, load_articles, update_article, Article}; use common::models::article::{delete_article, insert_article, load_article, load_articles, update_article, Article, article_add_nutrition};
use common::models::origin::Origin; use common::models::origin::Origin;
use sqlx::{ postgres::PgPoolOptions, PgPool }; use sqlx::{ postgres::PgPoolOptions, PgPool };
use tower_http::cors::{AllowOrigin, Any, CorsLayer}; use tower_http::cors::{AllowOrigin, Any, CorsLayer};
use tracing::info; use tracing::info;
use http::header::{AUTHORIZATION, ACCEPT, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, ACCESS_CONTROL_ALLOW_CREDENTIALS}; use http::header::{AUTHORIZATION, ACCEPT, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_TYPE, ACCESS_CONTROL_ALLOW_CREDENTIALS};
use common::models::article; use common::models::{article, nutrition};
use common::models::label::{delete_label, insert_label, load_labels, update_label, Label}; use common::models::label::{delete_label, insert_label, load_labels, update_label, Label};
use common::models::nutrition::{insert_nutrition, Nutrition, delete_nutrition, update_nutrition};
use common::models::settings::{load_settings, update_settings, Settings}; use common::models::settings::{load_settings, update_settings, Settings};
use common::models::supplier::{delete_supplier, insert_supplier, load_suppliers, update_supplier, Supplier}; use common::models::supplier::{delete_supplier, insert_supplier, load_suppliers, update_supplier, Supplier};
use common::models::unit::Unit; use common::models::unit::Unit;
@@ -68,6 +69,9 @@ async fn main() {
.route("/supplier", post(add_supplier_route)) .route("/supplier", post(add_supplier_route))
.route("/supplier/{id}", post(update_supplier_route)) .route("/supplier/{id}", post(update_supplier_route))
.route("/supplier/{id}", delete(delete_supplier_route)) .route("/supplier/{id}", delete(delete_supplier_route))
.route("/article/{id}/nutrition", post(create_article_nutrition_route))
.route("/nutrition/{id}", post(update_nutrition_route))
.route("/article/{id}/nutrition", delete(delete_nutrition_route))
.with_state(pool) .with_state(pool)
.layer(cors); .layer(cors);
@@ -125,7 +129,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 +164,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 +201,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 +253,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 +286,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))
@@ -518,3 +522,58 @@ async fn delete_supplier_route(
} }
} }
} }
async fn create_article_nutrition_route(
State(pool): State<PgPool>,
Path(article_id): Path<i64>,
) -> (StatusCode, Json<Article>) {
info!("Add nutrition to article");
match article_add_nutrition(article_id, pool).await {
Some(article) => {
(StatusCode::CREATED, Json(article))
}
None => {
(StatusCode::INTERNAL_SERVER_ERROR, Json(Article::default()))
}
}
}
async fn update_nutrition_route(
State(pool): State<PgPool>,
Path(nutrition_id): Path<i64>,
Json(payload): Json<Nutrition>,
) -> (StatusCode, Json<Nutrition>) {
info!("Update nutrition");
let update_nutrition = update_nutrition(nutrition_id, &payload, pool).await;
match update_nutrition {
Some(nutrition) => {
(StatusCode::OK, Json(nutrition))
}
None => {
let nutrition = Nutrition::default();
(StatusCode::INTERNAL_SERVER_ERROR, Json(nutrition))
}
}
}
async fn delete_nutrition_route(
State(pool): State<PgPool>,
Path(nutrition_id): Path<i64>,
) -> StatusCode {
info!("Delete nutrition");
let delete_article_result = delete_nutrition(nutrition_id, pool).await;
match delete_article_result {
Some(_) => {
StatusCode::OK
}
None => {
StatusCode::INTERNAL_SERVER_ERROR
}
}
}