lootaherra identifier

This commit is contained in:
Jani Pulkkinen
2025-06-18 20:34:38 +03:00
parent 1993245a90
commit 42a0063e0f

View File

@@ -193,45 +193,69 @@ async fn get_admin(path: web::Path<String>) -> impl Responder {
}
}
#[get("/lootaherra/orders")]
async fn get_admin_orders() -> impl Responder {
let orders = web::block(move || {
let conn = &mut establish_connection();
find_admin_orders(conn)
})
.await;
#[get("/lootaherra/{identifier}/orders")]
async fn get_admin_orders(path: web::Path<String>) -> impl Responder {
let identifier_param = path.into_inner();
match orders {
Ok(Ok(response)) => HttpResponse::Ok()
.content_type(APPLICATION_JSON)
.json(response),
let exists = web::block(move || find_admin(identifier_param)).await.unwrap();
_ => HttpResponse::NotFound()
match exists {
true => {
let orders = web::block(move || {
let conn = &mut establish_connection();
find_admin_orders(conn)
})
.await;
match orders {
Ok(Ok(response)) => HttpResponse::Ok()
.content_type(APPLICATION_JSON)
.json(response),
_ => HttpResponse::NotFound()
.content_type(APPLICATION_JSON)
.await
.unwrap(),
}
},
_ => HttpResponse::Forbidden()
.content_type(APPLICATION_JSON)
.await
.unwrap(),
}
}
#[get("/lootaherra/box-list/{delivery_date}")]
async fn get_admin_boxes(path: web::Path<String>) -> impl Responder {
let _delivery_date = path.into_inner();
#[get("/lootaherra/{identifier}/box-list/{delivery_date}")]
async fn get_admin_boxes(path: web::Path<(String, String)>) -> impl Responder {
let (identifier_param, delivery_date_param) = path.into_inner();
let boxes = web::block(move || {
let conn = &mut establish_connection();
find_admin_boxes(_delivery_date, conn)
})
.await;
let exists = web::block(move || find_admin(identifier_param)).await.unwrap();
match boxes {
Ok(Ok(response)) => HttpResponse::Ok()
.content_type(APPLICATION_JSON)
.json(response),
_ => HttpResponse::NotFound()
match exists {
true => {
let boxes = web::block(move || {
let conn = &mut establish_connection();
find_admin_boxes(delivery_date_param, conn)
})
.await;
match boxes {
Ok(Ok(response)) => HttpResponse::Ok()
.content_type(APPLICATION_JSON)
.json(response),
_ => HttpResponse::NotFound()
.content_type(APPLICATION_JSON)
.await
.unwrap(),
}
},
_ => HttpResponse::Forbidden()
.content_type(APPLICATION_JSON)
.await
.unwrap(),
.unwrap()
}
}
#[get("/loota/{id}")]