small fix
This commit is contained in:
@@ -40,4 +40,9 @@ joinable!(claims -> looted (loot_id));
|
|||||||
joinable!(claims -> players (player_id));
|
joinable!(claims -> players (player_id));
|
||||||
joinable!(looted -> players (owner_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="icon" href="<%= BASE_URL %>favicon.ico">
|
||||||
<link rel="stylesheet" href="<%= BASE_URL %>css/scroll.css">
|
<link rel="stylesheet" href="<%= BASE_URL %>css/scroll.css">
|
||||||
<title>Loot-a-Lot !</title>
|
<title>Loot-a-Lot !</title>
|
||||||
<script defer src="fontawesome/js/all.js"></script>
|
<script defer src="<%= BASE_URL %>fontawesome/js/all.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app"></div>
|
<div id="app"></div>
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use futures::Future;
|
|||||||
use lootalot_db::{DbApi, Pool, QueryResult};
|
use lootalot_db::{DbApi, Pool, QueryResult};
|
||||||
use std::env;
|
use std::env;
|
||||||
use serde::{Serialize, Deserialize};
|
use serde::{Serialize, Deserialize};
|
||||||
|
|
||||||
type AppPool = web::Data<Pool>;
|
type AppPool = web::Data<Pool>;
|
||||||
|
|
||||||
/// Wraps call to the DbApi and process its result as a async HttpResponse
|
/// 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<
|
pub fn db_call<J,Q>(
|
||||||
J: serde::ser::Serialize + Send + 'static,
|
|
||||||
Q: Fn(DbApi) -> QueryResult<J> + Send + 'static,
|
|
||||||
>(
|
|
||||||
pool: AppPool,
|
pool: AppPool,
|
||||||
query: Q,
|
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();
|
let conn = pool.get().unwrap();
|
||||||
web::block(move || {
|
web::block(move || {
|
||||||
let api = DbApi::with_conn(&conn);
|
let api = DbApi::with_conn(&conn);
|
||||||
query(api)
|
query(api)
|
||||||
})
|
})
|
||||||
.then(|res| match res {
|
.then(|res| match res {
|
||||||
Ok(players) => HttpResponse::Ok().json(players),
|
Ok(players) => HttpResponse::Ok().json(players),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
dbg!(&e);
|
dbg!(&e);
|
||||||
HttpResponse::InternalServerError().finish()
|
HttpResponse::InternalServerError().finish()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Debug)]
|
#[derive(Serialize, Deserialize, Debug)]
|
||||||
@@ -83,7 +84,7 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
|||||||
.data(pool.clone())
|
.data(pool.clone())
|
||||||
.wrap(
|
.wrap(
|
||||||
Cors::new()
|
Cors::new()
|
||||||
.allowed_origin("http://localhost:8080")
|
.allowed_origin("http://localhost:8088")
|
||||||
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
.allowed_methods(vec!["GET", "POST", "PUT", "DELETE", "OPTIONS"])
|
||||||
.max_age(3600),
|
.max_age(3600),
|
||||||
)
|
)
|
||||||
@@ -113,25 +114,25 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
|||||||
db_call(pool, move |api| api
|
db_call(pool, move |api| api
|
||||||
.as_player(data.player_id)
|
.as_player(data.player_id)
|
||||||
.update_wealth(data.value_in_gp))
|
.update_wealth(data.value_in_gp))
|
||||||
})
|
}),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/buy",
|
"/buy",
|
||||||
web::post().to_async(move |pool: AppPool, data: web::Json<LootUpdate>| {
|
web::post().to_async(move |pool: AppPool, data: web::Json<LootUpdate>| {
|
||||||
db_call(pool, move |api| api
|
db_call(pool, move |api| api
|
||||||
.as_player(data.player_id)
|
.as_player(data.player_id)
|
||||||
.buy(&data.items)
|
.buy(&data.items),
|
||||||
)
|
)
|
||||||
})
|
}),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/sell",
|
"/sell",
|
||||||
web::post().to_async(move |pool: AppPool, data: web::Json<LootUpdate>| {
|
web::post().to_async(move |pool: AppPool, data: web::Json<LootUpdate>| {
|
||||||
db_call(pool, move |api| api
|
db_call(pool, move |api| api
|
||||||
.as_player(data.player_id)
|
.as_player(data.player_id)
|
||||||
.sell(&data.items)
|
.sell(&data.items),
|
||||||
)
|
)
|
||||||
})
|
}),
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.service(
|
.service(
|
||||||
@@ -167,7 +168,7 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
|||||||
move |pool: AppPool, data: web::Json<NewPlayer>| {
|
move |pool: AppPool, data: web::Json<NewPlayer>| {
|
||||||
db_call(pool, move |api| api
|
db_call(pool, move |api| api
|
||||||
.as_admin()
|
.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"))
|
.service(fs::Files::new("/", www_root.clone()).index_file("index.html"))
|
||||||
})
|
})
|
||||||
.bind("127.0.0.1:8088")?
|
.bind("127.0.0.1:8088")?
|
||||||
.run()
|
.run()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user