From 1c09b0eb5db415985bfefb52786dbe48d757665e Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Sat, 6 Sep 2025 18:31:40 +0200 Subject: feat: Provide basic barcode handling support --- crates/rocie-server/src/api/set/unit.rs | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 crates/rocie-server/src/api/set/unit.rs (limited to 'crates/rocie-server/src/api/set/unit.rs') diff --git a/crates/rocie-server/src/api/set/unit.rs b/crates/rocie-server/src/api/set/unit.rs new file mode 100644 index 0000000..4281e05 --- /dev/null +++ b/crates/rocie-server/src/api/set/unit.rs @@ -0,0 +1,49 @@ +use actix_web::{HttpResponse, Responder, Result, post, web}; +use serde::Deserialize; +use utoipa::ToSchema; + +use crate::{app::App, storage::sql::{insert::Operations, unit::{Unit, UnitId}}}; + +#[derive(Deserialize, ToSchema)] +struct UnitStub { + full_name_plural: String, + full_name_singular: String, + short_name: String, + description: Option, +} + +/// Register an Unit +#[utoipa::path( + responses( + ( + status = 200, + description = "Product successfully registered in database", + body = UnitId, + ), + ( + status = INTERNAL_SERVER_ERROR, + description = "Server encountered error", + body = String, + ) + ), + request_body = UnitStub, +)] +#[post("/unit/new")] +pub(crate) async fn register_unit( + app: web::Data, + unit: web::Json, +) -> Result { + let mut ops = Operations::new("register unit"); + + let unit = Unit::register( + unit.full_name_singular.clone(), + unit.full_name_plural.clone(), + unit.short_name.clone(), + unit.description.clone(), + &mut ops, + ); + + ops.apply(&app).await?; + + Ok(HttpResponse::Ok().json(unit.id)) +} -- cgit 1.4.1