group
This commit is contained in:
parent
fb6a96ff55
commit
94459d5481
7 changed files with 90 additions and 14 deletions
|
@ -69,14 +69,15 @@ pub async fn demand_route(f: Json<DemandForm>, t: Token, c: &State<Config>) -> F
|
|||
Ok(json!({"ok": 1}))
|
||||
}
|
||||
|
||||
/// Returns all used transactions for Item Variant
|
||||
#[get("/item/<item_id>/<variant_id>/demand")]
|
||||
/// Returns all consumed transactions for Item Variant
|
||||
#[get("/item/<item_id>/<variant_id>/demand?<destination>")]
|
||||
pub async fn demand_log_route(
|
||||
item_id: &str,
|
||||
variant_id: &str,
|
||||
itemdb: &State<ItemDB>,
|
||||
t: Token,
|
||||
c: &State<Config>,
|
||||
destination: Option<&str>,
|
||||
) -> FallibleApiResponse {
|
||||
check_auth!(t, c);
|
||||
|
||||
|
@ -86,7 +87,7 @@ pub async fn demand_log_route(
|
|||
.variant(variant_id)
|
||||
.ok_or_else(variant_does_not_exist_error)?;
|
||||
|
||||
let transactions = variant.demand_log().await;
|
||||
let transactions = variant.demand_log(destination).await;
|
||||
|
||||
Ok(json!(transactions))
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
mod demand;
|
||||
mod error;
|
||||
mod location;
|
||||
mod stat;
|
||||
mod supply;
|
||||
|
||||
pub use demand::*;
|
||||
|
@ -8,6 +9,7 @@ pub use error::*;
|
|||
pub use location::*;
|
||||
use mongod::Model;
|
||||
use mongod::ToAPI;
|
||||
pub use stat::*;
|
||||
pub use supply::*;
|
||||
|
||||
use rocket::get;
|
||||
|
|
32
src/routes/item/stat.rs
Normal file
32
src/routes/item/stat.rs
Normal file
|
@ -0,0 +1,32 @@
|
|||
use rocket::{get, State};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::check_auth;
|
||||
use crate::config::Config;
|
||||
use crate::routes::Token;
|
||||
use crate::{
|
||||
db::ItemDB,
|
||||
routes::{api_error, FallibleApiResponse},
|
||||
};
|
||||
|
||||
use super::{item_does_not_exist_error, variant_does_not_exist_error};
|
||||
|
||||
#[get("/item/<item_id>/<variant_id>/price_history?<origin>")]
|
||||
pub async fn variant_price_history_by_origin(
|
||||
item_id: &str,
|
||||
variant_id: &str,
|
||||
itemdb: &State<ItemDB>,
|
||||
t: Token,
|
||||
c: &State<Config>,
|
||||
origin: &str,
|
||||
) -> FallibleApiResponse {
|
||||
check_auth!(t, c);
|
||||
|
||||
let variant = itemdb
|
||||
.get_item(item_id)
|
||||
.ok_or_else(item_does_not_exist_error)?
|
||||
.variant(variant_id)
|
||||
.ok_or_else(variant_does_not_exist_error)?;
|
||||
|
||||
Ok(json!(variant.price_history_by_origin(origin).await))
|
||||
}
|
|
@ -82,20 +82,25 @@ pub async fn supply_log_route(
|
|||
}
|
||||
|
||||
/// Returns current active Transactions for Item
|
||||
#[get("/item/<item_id>/inventory")]
|
||||
#[get("/item/<item_id>/inventory?<origin>")]
|
||||
pub async fn inventory_route(
|
||||
item_id: &str,
|
||||
itemdb: &State<ItemDB>,
|
||||
t: Token,
|
||||
c: &State<Config>,
|
||||
origin: Option<&str>,
|
||||
) -> FallibleApiResponse {
|
||||
check_auth!(t, c);
|
||||
|
||||
let variant = itemdb
|
||||
let item = itemdb
|
||||
.get_item(item_id)
|
||||
.ok_or_else(item_does_not_exist_error)?;
|
||||
|
||||
let transactions = variant.inventory().await;
|
||||
let transactions = if let Some(origin) = origin {
|
||||
item.inventory_by_origin(origin).await
|
||||
} else {
|
||||
item.inventory().await
|
||||
};
|
||||
|
||||
Ok(json!(mongod::vec_to_api(&transactions).await))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue