From c91dce4f77ae12453203f0a28b91efb6533cc095 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Tue, 9 Dec 2025 13:07:14 +0100 Subject: feat(rocie-server): Implement basic user handling and authentication --- crates/rocie-server/src/api/set/barcode.rs | 105 ----------------------------- 1 file changed, 105 deletions(-) delete mode 100644 crates/rocie-server/src/api/set/barcode.rs (limited to 'crates/rocie-server/src/api/set/barcode.rs') diff --git a/crates/rocie-server/src/api/set/barcode.rs b/crates/rocie-server/src/api/set/barcode.rs deleted file mode 100644 index bb84bbf..0000000 --- a/crates/rocie-server/src/api/set/barcode.rs +++ /dev/null @@ -1,105 +0,0 @@ -use actix_web::{HttpResponse, Responder, Result, post, web}; -use log::debug; - -use crate::{ - app::App, - storage::sql::{ - barcode::{Barcode, BarcodeId, BarcodeIdStub}, - insert::Operations, - unit::UnitAmount, - }, -}; - -/// Buy an barcode -#[utoipa::path( - responses( - ( - status = OK, - description = "Barcode successfully bought", - ), - ( - status = NOT_FOUND, - description = "Barcode id was not found", - ), - ( - status = INTERNAL_SERVER_ERROR, - description = "Server encountered error", - body = String, - ) - ), - params( - ("barcode_id" = BarcodeId, description = "The numeric value of the barcode"), - ("times" = u16, description = "How often to buy the barcode"), - ) -)] -#[post("/barcode/{barcode_id}/buy/{times}")] -pub(crate) async fn buy_barcode( - app: web::Data, - path: web::Path<(BarcodeIdStub, u16)>, -) -> Result { - let (barcode_id, times) = path.into_inner(); - - let mut ops = Operations::new("buy barcode unit"); - - let barcode = Barcode::from_id(&app, barcode_id.into()).await?; - - match barcode { - Some(barcode) => { - for _ in 0..times { - barcode.buy(&mut ops); - } - - ops.apply(&app).await?; - - Ok(HttpResponse::Ok().finish()) - } - None => Ok(HttpResponse::NotFound().finish()), - } -} - -/// Consume an barcode -#[utoipa::path( - responses( - ( - status = OK, - description = "Barcode successfully consumed", - ), - ( - status = NOT_FOUND, - description = "Barcode id was not found", - ), - ( - status = INTERNAL_SERVER_ERROR, - description = "Server encountered error", - body = String, - ) - ), - params( - ("id" = BarcodeId, description = "The numeric value of the barcode"), - ), - request_body = UnitAmount, -)] -#[post("/barcode/{id}/consume")] -pub(crate) async fn consume_barcode( - app: web::Data, - barcode_id: web::Path, - unit_amount: web::Json, -) -> Result { - let mut ops = Operations::new("consume barcode unit"); - - let barcode = Barcode::from_id(&app, barcode_id.into_inner().into()).await?; - debug!("Starting consume for barcode: {barcode:?}"); - - match barcode { - Some(barcode) => { - barcode - .consume(&app, unit_amount.into_inner(), &mut ops) - .await?; - - ops.apply(&app).await?; - - Ok(HttpResponse::Ok().finish()) - } - None => Ok(HttpResponse::NotFound().finish()), - } -} -- cgit 1.4.1