diff --git a/lootalot_db/src/schema.rs b/lootalot_db/src/schema.rs index 3989f64..5e7b23e 100644 --- a/lootalot_db/src/schema.rs +++ b/lootalot_db/src/schema.rs @@ -40,4 +40,9 @@ joinable!(claims -> looted (loot_id)); joinable!(claims -> players (player_id)); joinable!(looted -> players (owner_id)); -allow_tables_to_appear_in_same_query!(claims, items, looted, players,); +allow_tables_to_appear_in_same_query!( + claims, + items, + looted, + players, +); diff --git a/lootalot_front/public/index.html b/lootalot_front/public/index.html index c5ad155..7e378bd 100644 --- a/lootalot_front/public/index.html +++ b/lootalot_front/public/index.html @@ -8,7 +8,7 @@ Loot-a-Lot ! - +
diff --git a/src/server.rs b/src/server.rs index 711e84a..deb8488 100644 --- a/src/server.rs +++ b/src/server.rs @@ -5,6 +5,7 @@ use futures::Future; use lootalot_db::{DbApi, Pool, QueryResult}; use std::env; use serde::{Serialize, Deserialize}; + type AppPool = web::Data; /// Wraps call to the DbApi and process its result as a async HttpResponse @@ -28,25 +29,25 @@ type AppPool = web::Data; /// } /// ) /// ``` -pub fn db_call< - J: serde::ser::Serialize + Send + 'static, - Q: Fn(DbApi) -> QueryResult + Send + 'static, ->( +pub fn db_call( pool: AppPool, query: Q, -) -> impl Future { +) -> impl Future + where J: serde::ser::Serialize + Send + 'static, + Q: Fn(DbApi) -> QueryResult + Send + 'static, +{ let conn = pool.get().unwrap(); web::block(move || { let api = DbApi::with_conn(&conn); query(api) }) - .then(|res| match res { - Ok(players) => HttpResponse::Ok().json(players), - Err(e) => { - dbg!(&e); - HttpResponse::InternalServerError().finish() - } - }) + .then(|res| match res { + Ok(players) => HttpResponse::Ok().json(players), + Err(e) => { + dbg!(&e); + HttpResponse::InternalServerError().finish() + } + }) } #[derive(Serialize, Deserialize, Debug)] @@ -83,7 +84,7 @@ pub(crate) fn serve() -> std::io::Result<()> { .data(pool.clone()) .wrap( Cors::new() - .allowed_origin("http://localhost:8080") + .allowed_origin("http://localhost:8088") .allowed_methods(vec!["GET", "POST", "PUT", "DELETE", "OPTIONS"]) .max_age(3600), ) @@ -113,25 +114,25 @@ pub(crate) fn serve() -> std::io::Result<()> { db_call(pool, move |api| api .as_player(data.player_id) .update_wealth(data.value_in_gp)) - }) + }), ) .route( "/buy", web::post().to_async(move |pool: AppPool, data: web::Json| { db_call(pool, move |api| api .as_player(data.player_id) - .buy(&data.items) + .buy(&data.items), ) - }) + }), ) .route( "/sell", web::post().to_async(move |pool: AppPool, data: web::Json| { db_call(pool, move |api| api .as_player(data.player_id) - .sell(&data.items) + .sell(&data.items), ) - }) + }), ) ) .service( @@ -167,7 +168,7 @@ pub(crate) fn serve() -> std::io::Result<()> { move |pool: AppPool, data: web::Json| { db_call(pool, move |api| api .as_admin() - .add_player(&data.name, data.wealth) + .add_player(&data.name, data.wealth), ) }, ), @@ -176,6 +177,6 @@ pub(crate) fn serve() -> std::io::Result<()> { ) .service(fs::Files::new("/", www_root.clone()).index_file("index.html")) }) - .bind("127.0.0.1:8088")? - .run() + .bind("127.0.0.1:8088")? + .run() }