refactor
This commit is contained in:
parent
b8caa43972
commit
4295bdcb8d
7 changed files with 109 additions and 36 deletions
|
@ -5,6 +5,7 @@ use serde::Deserialize;
|
|||
use serde_json::json;
|
||||
|
||||
use crate::db::ItemDB;
|
||||
use crate::transaction::Transaction;
|
||||
use crate::variant::Variant;
|
||||
|
||||
use super::{api_error, ApiError, FallibleApiResponse};
|
||||
|
@ -77,6 +78,14 @@ pub fn get_items_route(itemdb: &State<ItemDB>) -> serde_json::Value {
|
|||
json!({"items": items})
|
||||
}
|
||||
|
||||
#[get("/item/<item_id>")]
|
||||
pub fn item_route(item_id: &str, itemdb: &State<ItemDB>) -> FallibleApiResponse {
|
||||
let item = itemdb
|
||||
.get_item(item_id)
|
||||
.ok_or_else(item_does_not_exist_error)?;
|
||||
Ok(item.api_json())
|
||||
}
|
||||
|
||||
#[get("/item/<item_id>/variants")]
|
||||
pub fn item_variants_page(item_id: &str, itemdb: &State<ItemDB>) -> FallibleApiResponse {
|
||||
let item = itemdb
|
||||
|
@ -123,3 +132,11 @@ pub async fn demand_log_route(
|
|||
|
||||
Ok(json!(transactions))
|
||||
}
|
||||
|
||||
#[get("/transaction/<transaction>")]
|
||||
pub async fn transaction_route(transaction: &str) -> FallibleApiResponse {
|
||||
let t = Transaction::get(transaction)
|
||||
.await
|
||||
.ok_or_else(|| api_error("No transaction with this UUID"))?;
|
||||
Ok(t.api_json())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue