move to api
This commit is contained in:
parent
c012683af1
commit
9da4ef072c
6 changed files with 14 additions and 35 deletions
34
src/main.rs
34
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<item::ItemDB> = 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("<script src=\"https://cdn.tailwindcss.com\"></script>".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
|
||||
|
|
|
@ -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)));
|
||||
};
|
||||
};
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
use maud::html;
|
||||
|
||||
pub fn button(title: &str, redir: &str) -> maud::PreEscaped<String> {
|
||||
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)
|
||||
};
|
||||
)
|
||||
}
|
Loading…
Reference in a new issue