small fix

This commit is contained in:
2019-10-01 15:43:16 +02:00
parent cb98b97126
commit 34bb1977a5
3 changed files with 29 additions and 23 deletions

View File

@@ -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,
);

View File

@@ -8,7 +8,7 @@
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
<link rel="stylesheet" href="<%= BASE_URL %>css/scroll.css">
<title>Loot-a-Lot !</title>
<script defer src="fontawesome/js/all.js"></script>
<script defer src="<%= BASE_URL %>fontawesome/js/all.js"></script>
</head>
<body>
<div id="app"></div>

View File

@@ -5,6 +5,7 @@ use futures::Future;
use lootalot_db::{DbApi, Pool, QueryResult};
use std::env;
use serde::{Serialize, Deserialize};
type AppPool = web::Data<Pool>;
/// Wraps call to the DbApi and process its result as a async HttpResponse
@@ -28,25 +29,25 @@ type AppPool = web::Data<Pool>;
/// }
/// )
/// ```
pub fn db_call<
J: serde::ser::Serialize + Send + 'static,
Q: Fn(DbApi) -> QueryResult<J> + Send + 'static,
>(
pub fn db_call<J,Q>(
pool: AppPool,
query: Q,
) -> impl Future<Item = HttpResponse, Error = Error> {
) -> impl Future<Item=HttpResponse, Error=Error>
where J: serde::ser::Serialize + Send + 'static,
Q: Fn(DbApi) -> QueryResult<J> + 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<LootUpdate>| {
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<LootUpdate>| {
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<NewPlayer>| {
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()
}