From 9da4ef072c24c4d38b442a041b8bdd03710ebaf0 Mon Sep 17 00:00:00 2001 From: JMARyA Date: Thu, 4 Apr 2024 07:41:13 +0200 Subject: [PATCH] move to api --- src/main.rs | 34 +++++++------------- src/{pages => routes}/item/inventory_page.rs | 0 src/{pages => routes}/item/mod.rs | 6 ++-- src/{pages => routes}/item/variant_pages.rs | 0 src/{pages => routes}/mod.rs | 0 src/ui/mod.rs | 9 ------ 6 files changed, 14 insertions(+), 35 deletions(-) rename src/{pages => routes}/item/inventory_page.rs (100%) rename src/{pages => routes}/item/mod.rs (87%) rename src/{pages => routes}/item/variant_pages.rs (100%) rename src/{pages => routes}/mod.rs (100%) delete mode 100644 src/ui/mod.rs diff --git a/src/main.rs b/src/main.rs index c794606..4c3cc88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,8 +2,7 @@ use actix_web::{get, HttpRequest, Responder}; use maud::html; mod item; -mod pages; -mod ui; +mod routes; // ░░░░░░░░░░▀▀▀██████▄▄▄░░░░░░░░░░ // ░░░░░░░░░░░░░░░░░▀▀▀████▄░░░░░░░ @@ -23,14 +22,7 @@ mod ui; #[get("/")] pub(crate) async fn index(r: HttpRequest) -> impl Responder { let itemdb: &actix_web::web::Data = r.app_data().unwrap(); - - let content = html!( - p class="text-xl font-bold" { "Hello World" }; - @for item in itemdb.items() { - a href=(format!("/item/{}", item)) { (item) }; - } - ) - .into_string(); + let content = ""; web_base::func::build_site(&r, "Index", &content) } @@ -41,19 +33,15 @@ async fn main() -> std::io::Result<()> { let itemdb = item::ItemDB::new("./itemdb", "mongodb://user:pass@127.0.0.1:27017").await; let itemdb = actix_web::web::Data::new(itemdb); - web_base::map!( - web_base::Site::new() - .head_content("".to_string()), - |app: actix_web::App<_>| { - app.app_data(itemdb.clone()) - .service(index) - .service(pages::item::item_page) - .service(pages::item::variant_pages::add_item_variant_page) - .service(pages::item::variant_pages::add_item_variant_page_post) - .service(pages::item::inventory_page::add_item_inventory_page) - .service(pages::item::inventory_page::add_item_inventory_page_post) - } - ) + web_base::map!(web_base::Site::new(), |app: actix_web::App<_>| { + app.app_data(itemdb.clone()) + .service(index) + .service(routes::item::item_page) + .service(routes::item::variant_pages::add_item_variant_page) + .service(routes::item::variant_pages::add_item_variant_page_post) + .service(routes::item::inventory_page::add_item_inventory_page) + .service(routes::item::inventory_page::add_item_inventory_page_post) + }) .bind(("0.0.0.0".to_string(), 8080))? .run() .await diff --git a/src/pages/item/inventory_page.rs b/src/routes/item/inventory_page.rs similarity index 100% rename from src/pages/item/inventory_page.rs rename to src/routes/item/inventory_page.rs diff --git a/src/pages/item/mod.rs b/src/routes/item/mod.rs similarity index 87% rename from src/pages/item/mod.rs rename to src/routes/item/mod.rs index 89464db..a6e1973 100644 --- a/src/pages/item/mod.rs +++ b/src/routes/item/mod.rs @@ -3,7 +3,7 @@ use maud::html; pub mod inventory_page; pub mod variant_pages; -use crate::{item, ui::button}; +use crate::item; #[get("/item/{item_id}")] pub async fn item_page(r: HttpRequest) -> impl Responder { @@ -23,8 +23,8 @@ pub async fn item_page(r: HttpRequest) -> impl Responder { p class="font-bold" { (format!("Category: {}", item.item.category))}; }; div class="mt-5" { - (button("Add Variant", &format!("/item/{}/variant/add", item.item.name))) - (button("Add inventory", &format!("/item/{}/inventory/add", item.item.name))); + // (button("Add Variant", &format!("/item/{}/variant/add", item.item.name))) + // (button("Add inventory", &format!("/item/{}/inventory/add", item.item.name))); }; }; diff --git a/src/pages/item/variant_pages.rs b/src/routes/item/variant_pages.rs similarity index 100% rename from src/pages/item/variant_pages.rs rename to src/routes/item/variant_pages.rs diff --git a/src/pages/mod.rs b/src/routes/mod.rs similarity index 100% rename from src/pages/mod.rs rename to src/routes/mod.rs diff --git a/src/ui/mod.rs b/src/ui/mod.rs deleted file mode 100644 index b57c6f7..0000000 --- a/src/ui/mod.rs +++ /dev/null @@ -1,9 +0,0 @@ -use maud::html; - -pub fn button(title: &str, redir: &str) -> maud::PreEscaped { - html!( - a class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded hover:cursor-pointer mt-1 mr-1 mb-1" href=(redir) { - (title) - }; - ) -}