adds buy/sell endpoints

This commit is contained in:
2019-08-07 15:34:08 +02:00
parent 6e7a0f6211
commit cb98b97126
5 changed files with 149 additions and 47 deletions

View File

@@ -67,6 +67,12 @@ struct NewPlayer {
wealth: f32,
}
#[derive(Serialize, Deserialize, Debug)]
struct LootUpdate {
player_id: i32,
items: Vec<(i32, Option<f32>)>,
}
pub(crate) fn serve() -> std::io::Result<()> {
let www_root: String = env::var("WWW_ROOT").expect("WWW_ROOT must be set");
dbg!(&www_root);
@@ -109,6 +115,24 @@ pub(crate) fn serve() -> std::io::Result<()> {
.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)
)
})
)
.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)
)
})
)
)
.service(
web::resource("/claims")