work
This commit is contained in:
parent
e8e8d9d960
commit
c012683af1
10 changed files with 384 additions and 30 deletions
36
src/main.rs
36
src/main.rs
|
@ -1,14 +1,17 @@
|
|||
use actix_web::{get, HttpRequest, Responder};
|
||||
use maud::html;
|
||||
|
||||
mod item;
|
||||
mod pages;
|
||||
mod ui;
|
||||
|
||||
// ░░░░░░░░░░▀▀▀██████▄▄▄░░░░░░░░░░
|
||||
// ░░░░░░░░░░░░░░░░░▀▀▀████▄░░░░░░░
|
||||
// ░░░░░░░░░░▄███████▀░░░▀███▄░░░░░
|
||||
// ░░░░░░░░▄███████▀░░░░░░░▀███▄░░░
|
||||
// ░░░░░░▄████████░░░░░░░░░░░███▄░░
|
||||
// ░░░░░██████████▄░░░░░░░░░░░███▌░ ▒█▀▀█ █▀▀█ █▀▄▀█ █▀▄▀█ ▒█▀▀▄ ▒█▀▀█
|
||||
// ░░░░░▀█████▀░▀███▄░░░░░░░░░▐███░ ▒█░░░ █░░█ █░▀░█ █░▀░█ ▒█░▒█ ▒█▀▀▄
|
||||
// ░░░░░██████████▄░░░░░░░░░░░███▌░ ▒█▀▀█ █▀▀█ █▀▄▀█ █▀▄▀█ ▒█▀▀▄ ▒█▀▀█
|
||||
// ░░░░░▀█████▀░▀███▄░░░░░░░░░▐███░ ▒█░░░ █░░█ █░▀░█ █░▀░█ ▒█░▒█ ▒█▀▀▄
|
||||
// ░░░░░░░▀█▀░░░░░▀███▄░░░░░░░▐███░ ▒█▄▄█ ▀▀▀▀ ▀░░░▀ ▀░░░▀ ▒█▄▄▀ ▒█▄▄█
|
||||
// ░░░░░░░░░░░░░░░░░▀███▄░░░░░███▌░
|
||||
// ░░░░▄██▄░░░░░░░░░░░▀███▄░░▐███░░
|
||||
|
@ -17,23 +20,6 @@ mod item;
|
|||
// ░████▀░░░▀▀█████▄▄▄▄█████████▄░░
|
||||
// ░░▀▀░░░░░░░░░▀▀██████▀▀░░░▀▀██░░
|
||||
|
||||
#[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!(
|
||||
p { "Item" };
|
||||
p { (format!("Category: {}", item.category))}
|
||||
).into_string();
|
||||
|
||||
web_base::build_site(&r, "Item", &content)
|
||||
}
|
||||
|
||||
#[get("/")]
|
||||
pub(crate) async fn index(r: HttpRequest) -> impl Responder {
|
||||
let itemdb: &actix_web::web::Data<item::ItemDB> = r.app_data().unwrap();
|
||||
|
@ -52,13 +38,21 @@ pub(crate) async fn index(r: HttpRequest) -> impl Responder {
|
|||
async fn main() -> std::io::Result<()> {
|
||||
env_logger::init();
|
||||
|
||||
let itemdb = item::ItemDB::new("./itemdb", "mongodb://user:pass@mongodb:27017").await;
|
||||
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(item_page) }
|
||||
|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)
|
||||
}
|
||||
)
|
||||
.bind(("0.0.0.0".to_string(), 8080))?
|
||||
.run()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue