cdb/src/routes/item/mod.rs

51 lines
1.7 KiB
Rust
Raw Normal View History

2024-01-16 09:02:23 +01:00
use actix_web::{get, HttpRequest, Responder};
use maud::html;
pub mod inventory_page;
pub mod variant_pages;
2024-04-04 07:41:13 +02:00
use crate::item;
2024-01-16 09:02:23 +01:00
#[get("/item/{item_id}")]
pub async fn item_page(r: HttpRequest) -> impl Responder {
let id = r.match_info().query("item_id");
println!("{}", id);
let itemdb: &actix_web::web::Data<item::ItemDB> = r.app_data().unwrap();
let item = itemdb.get_item(id).unwrap();
let content =
html!(
div class="bg-gray-100 min-h-screen min-w-screen items-center justify-center py-5" {
div class="w-screen px-5" {
div {
p class="mb-2 font-bold text-2xl" { (format!("Item : {}", item.item.name)) };
p class="font-bold" { (format!("Category: {}", item.item.category))};
};
div class="mt-5" {
2024-04-04 07:41:13 +02:00
// (button("Add Variant", &format!("/item/{}/variant/add", item.item.name)))
// (button("Add inventory", &format!("/item/{}/inventory/add", item.item.name)));
2024-01-16 09:02:23 +01:00
};
};
div class="mt-5 px-5" {
h1 class="text-2xl font-bold mb-4" { "Variants" };
@for variant in item.get_variants().await {
p class="mb-2" { (variant) };
}
@for q in item.get_inventory_entries().await {
div class="p-2" {
p { (format!("Variant {}", q.variant_name))};
p { (format!("Origin {}", q.origin))};
p { (format!("Price {}", q.price))};
};
}
};
};
)
.into_string();
web_base::build_site(&r, "Item", &content)
}