From 8d15e786ace69ed83aa1b17f716d64b2ebf5ca9a Mon Sep 17 00:00:00 2001 From: Matthias Lodner Date: Sat, 31 Jan 2026 04:10:51 +0100 Subject: [PATCH] Added data label for backend. --- common/src/models/article.rs | 2 +- common/src/models/label.rs | 148 ++++++++++++++++++ common/src/models/mod.rs | 1 + common/src/models/variant.rs | 45 +++++- .../app/components/variant/variantRow.vue | 7 +- frontend/app/types/label.ts | 9 ++ frontend/app/types/variant.ts | 9 +- .../migrations/20260131020351_add_label.sql | 17 ++ server/src/main.rs | 4 + 9 files changed, 231 insertions(+), 11 deletions(-) create mode 100644 common/src/models/label.rs create mode 100644 frontend/app/types/label.ts create mode 100644 server/migrations/20260131020351_add_label.sql diff --git a/common/src/models/article.rs b/common/src/models/article.rs index 4885fd9..4eb9ce6 100644 --- a/common/src/models/article.rs +++ b/common/src/models/article.rs @@ -33,7 +33,7 @@ fn from_postgres_row_small(row: PgRow) -> Article { } async fn from_postgres_row(row: PgRow, pool: PgPool) -> Article { - let variants_option = load_article_variants(row.get(0), pool).await; + let variants_option = load_article_variants(row.get(0), &pool).await; let variants = match variants_option { Some(variants_inner) => { diff --git a/common/src/models/label.rs b/common/src/models/label.rs new file mode 100644 index 0000000..b2b7aad --- /dev/null +++ b/common/src/models/label.rs @@ -0,0 +1,148 @@ +use log::{error, info}; +use serde::{Deserialize, Serialize}; +use sqlx::{Arguments, Decode, Encode, FromRow, PgPool, Row}; +use sqlx::postgres::{PgArguments, PgRow}; + +#[derive(Debug, Deserialize, Serialize, Clone, FromRow, Decode, Encode)] +pub struct Label { + pub id: i64, + pub name: String, +} + +fn from_postgres_row_small(row: PgRow) -> Label { + Label { + id: row.get(0), + name: row.get(1), + } +} + +pub async fn load_labels(pool: PgPool) -> Option> { + let statement = format!( + "SELECT * FROM {}", + "label", + ); + + let res = sqlx::query( + statement.as_str()) + .fetch_all(&pool).await; + + let mut labels: Vec