add latest price route

This commit is contained in:
JMARyA 2024-09-16 08:10:26 +02:00
parent 0d4ed15460
commit 9c03d38f6e
Signed by: jmarya
GPG key ID: 901B2ADDF27C2263
3 changed files with 31 additions and 4 deletions

View file

@ -28,5 +28,29 @@ pub async fn variant_price_history_by_origin(
.variant(variant_id)
.ok_or_else(variant_does_not_exist_error)?;
Ok(json!(variant.price_history_by_origin(origin).await))
Ok(json!(variant.price_history_by_origin(origin, None).await))
}
#[get("/item/<item_id>/<variant_id>/price_latest?<origin>")]
pub async fn variant_price_latest_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, Some(1))
.await
.first()
.unwrap()))
}