small fix
This commit is contained in:
@@ -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,
|
||||
);
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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,13 +29,13 @@ 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);
|
||||
@@ -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),
|
||||
)
|
||||
},
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user