Added supplier and updated dependencies.

This commit is contained in:
2026-07-22 19:26:57 +02:00
parent cddd9a3956
commit 581439150f
16 changed files with 3585 additions and 3068 deletions
+7 -8
View File
@@ -1,6 +1,6 @@
[package]
name = "server"
version = "0.1.0"
version = "0.3.0"
edition = "2024"
authors = ["Matthias Lodner <matthias@lodner.de>"]
@@ -12,21 +12,20 @@ path = "src/main.rs"
common = {path = "../common"}
axum = "0.8.9"
tokio = { version = "1.52.3", default-features = false, features = ["full"] }
http = "1.4.1"
tower-http = {version = "0.6.11", features = ["cors"]}
tokio = { version = "1.53.1", default-features = false, features = ["full"] }
http = "1.4.2"
tower-http = {version = "0.7.0", features = ["cors"]}
tracing = "=0.1.44"
tracing-subscriber = "0.3.23"
serde = { version = "1.0.228", features = ["derive"] }
serde_json = "1.0.150"
serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0.151"
# Logging
env_logger = "0.11.10"
env_logger = "0.11.11"
# Database
sqlx = { version = "0.9.0", features = [ "runtime-async-std", "postgres", "chrono", "macros" ] }
# Etc.
dotenv = "0.15.0"
chrono = { version = "0.4.45" }
@@ -0,0 +1,11 @@
-- Add migration script here
CREATE TABLE supplier
(
id bigint NOT NULL GENERATED ALWAYS AS IDENTITY ( INCREMENT 1 START 1 ),
topm_id text NOT NULL,
name text NOT NULL,
bio_info text
);
-- Insert default values
INSERT INTO supplier (topm_id, name, bio_info) VALUES ('999', 'Lodner Gewürze', 'DE-ÖKO-006');
+88
View File
@@ -18,6 +18,7 @@ use http::header::{AUTHORIZATION, ACCEPT, ACCESS_CONTROL_ALLOW_ORIGIN, CONTENT_T
use common::models::article;
use common::models::label::{delete_label, insert_label, load_labels, update_label, Label};
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::unit::Unit;
use common::models::variant::{delete_variant, insert_variant, update_variant, Variant};
@@ -63,6 +64,10 @@ async fn main() {
.route("/label/{id}", delete(delete_label_route))
.route("/settings", get(get_settings_route))
.route("/settings", post(update_settings_route))
.route("/supplier", get(get_suppliers_route))
.route("/supplier", post(add_supplier_route))
.route("/supplier/{id}", post(update_supplier_route))
.route("/supplier/{id}", delete(delete_supplier_route))
.with_state(pool)
.layer(cors);
@@ -425,3 +430,86 @@ async fn update_settings_route(
}
}
}
#[tracing::instrument(ret)]
async fn get_suppliers_route(
State(pool): State<PgPool>,
) -> (StatusCode, Json<Vec<Supplier>>) {
info!("Get all suppliers");
match load_suppliers(pool).await {
Some(suppliers) => {
(StatusCode::OK, Json(suppliers))
}
None => {
(StatusCode::INTERNAL_SERVER_ERROR, Json(vec![]))
}
}
}
#[tracing::instrument(ret)]
async fn add_supplier_route(
State(pool): State<PgPool>,
Json(payload): Json<Supplier>,
) -> (StatusCode, Json<Supplier>) {
info!("Add supplier");
match insert_supplier(&payload, pool).await {
Some(supplier) => {
(StatusCode::OK, Json(supplier))
}
None => {
let supplier = Supplier {
id: 0,
topm_id: "".to_string(),
name: "".to_string(),
bio_info: None,
};
(StatusCode::INTERNAL_SERVER_ERROR, Json(supplier))
}
}
}
#[tracing::instrument(ret)]
async fn update_supplier_route(
State(pool): State<PgPool>,
Path(supplier_id): Path<i64>,
Json(payload): Json<Supplier>,
) -> (StatusCode, Json<Supplier>) {
info!("Update supplier");
match update_supplier(supplier_id, &payload, pool).await {
Some(supplier) => {
(StatusCode::OK, Json(supplier))
}
None => {
let supplier = Supplier {
id: 0,
topm_id: "".to_string(),
name: "".to_string(),
bio_info: None,
};
(StatusCode::INTERNAL_SERVER_ERROR, Json(supplier))
}
}
}
async fn delete_supplier_route(
State(pool): State<PgPool>,
Path(supplier_id): Path<i64>,
) -> StatusCode {
info!("Delete supplier");
let deleted_result = delete_supplier(supplier_id, pool).await;
match deleted_result {
Some(_) => {
StatusCode::OK
}
None => {
StatusCode::INTERNAL_SERVER_ERROR
}
}
}