This commit is contained in:
JMARyA 2024-09-12 10:58:49 +02:00
parent a8dfe5f0e9
commit 37475460e2
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
5 changed files with 93 additions and 2 deletions

View file

@ -16,6 +16,7 @@ use serde_json::json;
use crate::check_auth;
use crate::config::Config;
use crate::db::get_items_without_min_satisfied;
use crate::db::ItemDB;
use crate::routes::Token;
use crate::transaction::Transaction;
@ -108,3 +109,35 @@ pub async fn unique_field_route(
_ => Err(api_error("Unknown field")),
}
}
#[get("/items/expired")]
pub async fn expired_items_route(t: Token, c: &State<Config>) -> FallibleApiResponse {
check_auth!(t, c);
let t = Transaction::active_expired().await;
Ok(json!(t))
}
#[get("/items/min")]
pub async fn min_items_route(
itemdb: &State<ItemDB>,
t: Token,
c: &State<Config>,
) -> FallibleApiResponse {
check_auth!(t, c);
let t: Vec<_> = get_items_without_min_satisfied(&itemdb)
.await
.into_iter()
.map(|x| {
json!({
"item_variant": x.0,
"need": x.1
}
)
})
.collect();
Ok(json!(t))
}