This commit is contained in:
JMARyA 2024-08-28 09:38:10 +02:00
parent 92e2da9cae
commit acf5ebae78
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
6 changed files with 56 additions and 47 deletions

View file

@ -18,9 +18,10 @@ pub struct DemandForm {
price: String,
}
/// Consumes a Transaction with Price and Destination
#[post("/demand", data = "<f>")]
pub async fn demand_route(f: Json<DemandForm>) -> FallibleApiResponse {
let uuid = Variant::demand(
Variant::demand(
&f.uuid,
f.price
.clone()
@ -31,9 +32,10 @@ pub async fn demand_route(f: Json<DemandForm>) -> FallibleApiResponse {
.await
.ok_or_else(|| api_error("Demand failed"))?;
Ok(json!({"uuid": uuid}))
Ok(json!({"ok": 1}))
}
/// Returns all used transactions for Item Variant
#[get("/item/<item_id>/<variant_id>/demand")]
pub async fn demand_log_route(
item_id: &str,

View file

@ -18,6 +18,7 @@ pub struct SupplyForm {
origin: Option<String>,
}
/// Route for supply action. Creates a new Transaction for the specified Item Variant.
#[post("/supply", data = "<form>")]
pub async fn supply_route(form: Json<SupplyForm>, itemdb: &State<ItemDB>) -> FallibleApiResponse {
println!("{form:?}");
@ -40,6 +41,7 @@ pub async fn supply_route(form: Json<SupplyForm>, itemdb: &State<ItemDB>) -> Fal
Ok(json!({"uuid": transaction_id}))
}
/// Returns a list of Transaction UUIDs for the Item Variant
#[get("/item/<item_id>/<variant_id>/supply")]
pub async fn supply_log_route(
item_id: &str,
@ -57,6 +59,7 @@ pub async fn supply_log_route(
Ok(json!(transactions))
}
/// Returns current active Transactions for Item Variant
#[get("/item/<item_id>/<variant_id>/inventory")]
pub async fn inventory_route(
item_id: &str,
@ -77,6 +80,7 @@ pub async fn inventory_route(
.collect::<Vec<_>>()))
}
/// Returns statistics for the Item Variant
#[get("/item/<item_id>/<variant_id>/stat")]
pub async fn variant_stat_route(
item_id: &str,