aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-server/src/api/get
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-08 11:54:04 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-10-08 11:54:04 +0200
commit08cf86a44a9a7c513cd12cbc4a0bac7c029b9ded (patch)
tree88b202b25ec22b86f3b4df9f2022b7b23ec3cba1 /crates/rocie-server/src/api/get
parentchore(crates/rocie-client): Regenerate (diff)
downloadserver-08cf86a44a9a7c513cd12cbc4a0bac7c029b9ded.zip
feat(crates/rocie-server/unit-property): Init
Diffstat (limited to '')
-rw-r--r--crates/rocie-server/src/api/get/mod.rs3
-rw-r--r--crates/rocie-server/src/api/get/unit.rs36
-rw-r--r--crates/rocie-server/src/api/get/unit_property.rs68
3 files changed, 100 insertions, 7 deletions
diff --git a/crates/rocie-server/src/api/get/mod.rs b/crates/rocie-server/src/api/get/mod.rs
index 21684af..e21a120 100644
--- a/crates/rocie-server/src/api/get/mod.rs
+++ b/crates/rocie-server/src/api/get/mod.rs
@@ -3,11 +3,14 @@ use actix_web::web;
pub(crate) mod inventory;
pub(crate) mod product;
pub(crate) mod unit;
+pub(crate) mod unit_property;
pub(crate) fn register_paths(cfg: &mut web::ServiceConfig) {
cfg.service(product::product_by_id)
.service(product::products)
.service(unit::units)
.service(unit::unit_by_id)
+ .service(unit_property::unit_properties)
+ .service(unit_property::unit_property_by_id)
.service(inventory::amount_by_id);
}
diff --git a/crates/rocie-server/src/api/get/unit.rs b/crates/rocie-server/src/api/get/unit.rs
index 4854ea3..73aa626 100644
--- a/crates/rocie-server/src/api/get/unit.rs
+++ b/crates/rocie-server/src/api/get/unit.rs
@@ -5,8 +5,16 @@ use crate::{app::App, storage::sql::unit::{Unit, UnitId, UnitIdStub}};
/// Return all registered units
#[utoipa::path(
responses(
- (status = OK, description = "All units founds", body = Vec<Unit>),
- (status = INTERNAL_SERVER_ERROR, description = "Server encountered error", body = String)
+ (
+ status = OK,
+ description = "All units founds",
+ body = Vec<Unit>
+ ),
+ (
+ status = INTERNAL_SERVER_ERROR,
+ description = "Server encountered error",
+ body = String
+ )
),
)]
#[get("/units/")]
@@ -19,12 +27,26 @@ pub(crate) async fn units(app: web::Data<App>) -> Result<impl Responder> {
/// Get Unit by id
#[utoipa::path(
responses(
- (status = OK, description = "Unit found from database", body = Unit),
- (status = NOT_FOUND, description = "Unit not found in database"),
- (status = INTERNAL_SERVER_ERROR, description = "Server encountered error", body = String)
+ (
+ status = OK,
+ description = "Unit found from database",
+ body = Unit
+ ),
+ (
+ status = NOT_FOUND,
+ description = "Unit not found in database"
+ ),
+ (
+ status = INTERNAL_SERVER_ERROR,
+ description = "Server encountered error",
+ body = String
+ )
),
params(
- ("id" = UnitId, description = "Unit id" ),
+ (
+ "id" = UnitId,
+ description = "Unit id"
+ ),
)
)]
#[get("/unit/{id}")]
@@ -35,7 +57,7 @@ pub(crate) async fn unit_by_id(
let id = id.into_inner();
match Unit::from_id(&app, id.into()).await? {
- Some(product) => Ok(HttpResponse::Ok().json(product)),
+ Some(unit) => Ok(HttpResponse::Ok().json(unit)),
None => Ok(HttpResponse::NotFound().finish()),
}
}
diff --git a/crates/rocie-server/src/api/get/unit_property.rs b/crates/rocie-server/src/api/get/unit_property.rs
new file mode 100644
index 0000000..3160480
--- /dev/null
+++ b/crates/rocie-server/src/api/get/unit_property.rs
@@ -0,0 +1,68 @@
+use actix_web::{HttpResponse, Responder, Result, get, web};
+
+use crate::{
+ app::App,
+ storage::sql::{
+ unit_property::{UnitProperty, UnitPropertyId, UnitPropertyIdStub},
+ },
+};
+
+/// Return all registered unit properties
+#[utoipa::path(
+ responses(
+ (
+ status = OK,
+ description = "All unit properties founds",
+ body = Vec<UnitProperty>
+ ),
+ (
+ status = INTERNAL_SERVER_ERROR,
+ description = "Server encountered error",
+ body = String
+ )
+ ),
+)]
+#[get("/unit-properties/")]
+pub(crate) async fn unit_properties(app: web::Data<App>) -> Result<impl Responder> {
+ let all = UnitProperty::get_all(&app).await?;
+
+ Ok(HttpResponse::Ok().json(all))
+}
+
+/// Get Unit property by id
+#[utoipa::path(
+ responses(
+ (
+ status = OK,
+ description = "Unit property found from database",
+ body = UnitProperty
+ ),
+ (
+ status = NOT_FOUND,
+ description = "Unit Property not found in database"
+ ),
+ (
+ status = INTERNAL_SERVER_ERROR,
+ description = "Server encountered error",
+ body = String
+ )
+ ),
+ params(
+ (
+ "id" = UnitPropertyId,
+ description = "Unit Property id"
+ ),
+ )
+)]
+#[get("/unit-property/{id}")]
+pub(crate) async fn unit_property_by_id(
+ app: web::Data<App>,
+ id: web::Path<UnitPropertyIdStub>,
+) -> Result<impl Responder> {
+ let id = id.into_inner();
+
+ match UnitProperty::from_id(&app, id.into()).await? {
+ Some(unit_property) => Ok(HttpResponse::Ok().json(unit_property)),
+ None => Ok(HttpResponse::NotFound().finish()),
+ }
+}