2024-09-02 16:40:02 +00:00
|
|
|
use std::ops::Deref;
|
|
|
|
|
|
|
|
use json_store::JSONStore;
|
|
|
|
use location::Location;
|
2024-09-03 09:16:45 +00:00
|
|
|
|
2024-06-21 19:14:45 +00:00
|
|
|
use rocket::routes as route;
|
|
|
|
use rocket::{http::Method, launch};
|
2024-01-16 08:02:23 +00:00
|
|
|
|
2024-09-08 00:37:39 +00:00
|
|
|
mod config;
|
2024-05-03 16:22:59 +00:00
|
|
|
mod db;
|
2024-09-09 19:49:36 +00:00
|
|
|
mod flow;
|
2024-01-14 02:57:13 +00:00
|
|
|
mod item;
|
2024-09-02 16:40:02 +00:00
|
|
|
mod json_store;
|
|
|
|
mod location;
|
2024-04-04 05:41:13 +00:00
|
|
|
mod routes;
|
2024-05-03 16:22:59 +00:00
|
|
|
mod transaction;
|
|
|
|
mod variant;
|
2024-01-14 02:57:13 +00:00
|
|
|
|
|
|
|
// ░░░░░░░░░░▀▀▀██████▄▄▄░░░░░░░░░░
|
|
|
|
// ░░░░░░░░░░░░░░░░░▀▀▀████▄░░░░░░░
|
|
|
|
// ░░░░░░░░░░▄███████▀░░░▀███▄░░░░░
|
|
|
|
// ░░░░░░░░▄███████▀░░░░░░░▀███▄░░░
|
|
|
|
// ░░░░░░▄████████░░░░░░░░░░░███▄░░
|
2024-01-16 08:02:23 +00:00
|
|
|
// ░░░░░██████████▄░░░░░░░░░░░███▌░ ▒█▀▀█ █▀▀█ █▀▄▀█ █▀▄▀█ ▒█▀▀▄ ▒█▀▀█
|
|
|
|
// ░░░░░▀█████▀░▀███▄░░░░░░░░░▐███░ ▒█░░░ █░░█ █░▀░█ █░▀░█ ▒█░▒█ ▒█▀▀▄
|
2024-01-14 02:57:13 +00:00
|
|
|
// ░░░░░░░▀█▀░░░░░▀███▄░░░░░░░▐███░ ▒█▄▄█ ▀▀▀▀ ▀░░░▀ ▀░░░▀ ▒█▄▄▀ ▒█▄▄█
|
|
|
|
// ░░░░░░░░░░░░░░░░░▀███▄░░░░░███▌░
|
|
|
|
// ░░░░▄██▄░░░░░░░░░░░▀███▄░░▐███░░
|
|
|
|
// ░░▄██████▄░░░░░░░░░░░▀███▄███░░░
|
|
|
|
// ░█████▀▀████▄▄░░░░░░░░▄█████░░░░
|
|
|
|
// ░████▀░░░▀▀█████▄▄▄▄█████████▄░░
|
|
|
|
// ░░▀▀░░░░░░░░░▀▀██████▀▀░░░▀▀██░░
|
|
|
|
|
2024-06-21 19:14:45 +00:00
|
|
|
#[launch]
|
|
|
|
async fn rocket() -> _ {
|
2024-08-28 20:03:39 +00:00
|
|
|
env_logger::init();
|
|
|
|
|
2024-06-21 19:14:45 +00:00
|
|
|
let cors = rocket_cors::CorsOptions {
|
|
|
|
allowed_origins: rocket_cors::AllowedOrigins::all(),
|
|
|
|
allowed_methods: vec![Method::Get, Method::Post, Method::Options]
|
|
|
|
.into_iter()
|
|
|
|
.map(From::from)
|
|
|
|
.collect(),
|
|
|
|
allowed_headers: rocket_cors::AllowedHeaders::all(),
|
|
|
|
allow_credentials: true,
|
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
.to_cors()
|
|
|
|
.expect("error creating CORS options");
|
2024-01-14 02:57:13 +00:00
|
|
|
|
2024-05-10 08:56:07 +00:00
|
|
|
let itemdb = db::ItemDB::new("./itemdb").await;
|
2024-09-02 16:40:02 +00:00
|
|
|
let locations: JSONStore<Location> = JSONStore::new("./locations");
|
|
|
|
|
|
|
|
for location in locations.deref() {
|
2024-09-02 17:10:22 +00:00
|
|
|
location.1.clone().add(location.0).await;
|
2024-09-02 16:40:02 +00:00
|
|
|
}
|
2024-01-14 02:57:13 +00:00
|
|
|
|
2024-09-08 00:37:39 +00:00
|
|
|
let config = config::get_config();
|
|
|
|
|
2024-06-21 19:14:45 +00:00
|
|
|
rocket::build()
|
|
|
|
.mount(
|
|
|
|
"/",
|
|
|
|
route![
|
|
|
|
routes::item::get_items_route,
|
2024-06-22 00:05:22 +00:00
|
|
|
routes::item::item_route,
|
2024-06-21 19:14:45 +00:00
|
|
|
routes::item::item_variants_page,
|
|
|
|
routes::item::supply_log_route,
|
|
|
|
routes::item::demand_log_route,
|
|
|
|
routes::item::supply_route,
|
|
|
|
routes::item::demand_route,
|
2024-08-13 02:13:38 +00:00
|
|
|
routes::item::transaction_route,
|
2024-08-27 21:33:09 +00:00
|
|
|
routes::item::inventory_route,
|
2024-09-05 08:33:34 +00:00
|
|
|
routes::item::inventory_route_variant,
|
2024-08-28 20:03:39 +00:00
|
|
|
routes::item::variant_stat_route,
|
2024-09-02 16:43:42 +00:00
|
|
|
routes::item::unique_field_route,
|
|
|
|
routes::item::location_info,
|
2024-09-05 08:33:34 +00:00
|
|
|
routes::item::locations_info,
|
|
|
|
routes::item::locations_list
|
2024-06-21 19:14:45 +00:00
|
|
|
],
|
|
|
|
)
|
|
|
|
.manage(itemdb)
|
2024-09-02 16:40:02 +00:00
|
|
|
.manage(locations)
|
2024-09-08 00:37:39 +00:00
|
|
|
.manage(config)
|
2024-06-21 19:14:45 +00:00
|
|
|
.attach(cors)
|
2024-01-14 02:57:13 +00:00
|
|
|
}
|