This commit is contained in:
JMARyA 2024-09-05 10:33:34 +02:00
parent d70dabc271
commit 9e9c48e5dd
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
4 changed files with 39 additions and 3 deletions
src/routes/item

View file

@ -2,6 +2,7 @@ use std::{collections::HashMap, ops::Deref};
use mongod::ToAPI;
use rocket::{get, State};
use serde_json::json;
use crate::{
json_store::JSONStore,
@ -48,6 +49,17 @@ async fn location_api_resolve(
}
#[get("/locations")]
pub async fn locations_list(locations: &State<JSONStore<Location>>) -> FallibleApiResponse {
let mut lst = Vec::with_capacity(locations.len());
for id in locations.deref().keys() {
lst.push(id);
}
Ok(json!(lst))
}
#[get("/location_map")]
pub async fn locations_info(locations: &State<JSONStore<Location>>) -> FallibleApiResponse {
let mut root_locations = HashMap::new();

View file

@ -61,9 +61,21 @@ pub async fn supply_log_route(
Ok(json!(transactions))
}
/// Returns current active Transactions for Item
#[get("/item/<item_id>/inventory")]
pub async fn inventory_route(item_id: &str, itemdb: &State<ItemDB>) -> FallibleApiResponse {
let variant = itemdb
.get_item(item_id)
.ok_or_else(item_does_not_exist_error)?;
let transactions = variant.inventory().await;
Ok(json!(mongod::vec_to_api(&transactions).await))
}
/// Returns current active Transactions for Item Variant
#[get("/item/<item_id>/<variant_id>/inventory")]
pub async fn inventory_route(
pub async fn inventory_route_variant(
item_id: &str,
variant_id: &str,
itemdb: &State<ItemDB>,