refactor
This commit is contained in:
parent
3b0e8c1866
commit
ca364453a7
10 changed files with 341 additions and 604 deletions
|
@ -4,6 +4,7 @@ mod supply;
|
|||
|
||||
pub use demand::*;
|
||||
pub use error::*;
|
||||
use mongod::Model;
|
||||
pub use supply::*;
|
||||
|
||||
use rocket::get;
|
||||
|
@ -23,6 +24,7 @@ pub fn get_items_route(itemdb: &State<ItemDB>) -> serde_json::Value {
|
|||
json!({"items": items})
|
||||
}
|
||||
|
||||
/// Return an API Response for an `Item`
|
||||
#[get("/item/<item_id>")]
|
||||
pub fn item_route(item_id: &str, itemdb: &State<ItemDB>) -> FallibleApiResponse {
|
||||
let item = itemdb
|
||||
|
@ -31,6 +33,7 @@ pub fn item_route(item_id: &str, itemdb: &State<ItemDB>) -> FallibleApiResponse
|
|||
Ok(item.api_json())
|
||||
}
|
||||
|
||||
/// Returns all variants of an Item
|
||||
#[get("/item/<item_id>/variants")]
|
||||
pub fn item_variants_page(item_id: &str, itemdb: &State<ItemDB>) -> FallibleApiResponse {
|
||||
let item = itemdb
|
||||
|
@ -44,6 +47,7 @@ pub fn item_variants_page(item_id: &str, itemdb: &State<ItemDB>) -> FallibleApiR
|
|||
}))
|
||||
}
|
||||
|
||||
/// Returns an API Response for a `Transaction`
|
||||
#[get("/transaction/<transaction>")]
|
||||
pub async fn transaction_route(transaction: &str) -> FallibleApiResponse {
|
||||
let t = Transaction::get(transaction)
|
||||
|
|
|
@ -14,9 +14,8 @@ use super::{item_does_not_exist_error, variant_does_not_exist_error};
|
|||
pub struct SupplyForm {
|
||||
item: String,
|
||||
variant: String,
|
||||
amount: Option<usize>,
|
||||
price: String,
|
||||
origin: String,
|
||||
origin: Option<String>,
|
||||
}
|
||||
|
||||
#[post("/supply", data = "<form>")]
|
||||
|
@ -30,12 +29,11 @@ pub async fn supply_route(form: Json<SupplyForm>, itemdb: &State<ItemDB>) -> Fal
|
|||
|
||||
let transaction_id = variant
|
||||
.supply(
|
||||
form.amount.unwrap_or(1),
|
||||
form.price
|
||||
.clone()
|
||||
.try_into()
|
||||
.map_err(|()| api_error("Price malformed"))?,
|
||||
&form.origin,
|
||||
form.origin.as_deref(),
|
||||
)
|
||||
.await;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue