adds buy/sell endpoints
This commit is contained in:
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user