works on selling group items

This commit is contained in:
2019-10-20 22:03:06 +02:00
parent 05a08ea337
commit 74ee4a831b
3 changed files with 41 additions and 6 deletions

View File

@@ -10,7 +10,6 @@ use crate::api;
type AppPool = web::Data<db::Pool>;
type PlayerId = web::Path<i32>;
type ItemId = web::Json<i32>;
type ItemListWithMods = web::Json<Vec<(i32, Option<f64>)>>;
#[derive(Serialize, Deserialize, Debug)]
struct NewGroupLoot {
@@ -99,18 +98,21 @@ fn configure_app(config: &mut web::ServiceConfig) {
db_call(pool, Q::FetchLoot(*player))
}))
.route(web::put().to_async(
move |pool, (player, data): (PlayerId, ItemListWithMods)| {
move |pool, (player, data): (PlayerId, web::Json<api::ItemListWithMods>)| {
db_call(pool, Q::BuyItems(*player, data.into_inner()))
},
))
.route(web::post().to(
move |pool, (player, data): (PlayerId, web::Json<NewGroupLoot>)| {
forbidden_to_players(*player, (pool, Q::AddLoot(data.items.clone())))
forbidden_to_players(*player, (pool, Q::AddLoot(data.into_inner().items)))
},
))
.route(web::delete().to_async(
move |pool, (player, data): (PlayerId, ItemListWithMods)| {
db_call(pool, Q::SellItems(*player, data.into_inner()))
move |pool, (player, data): (PlayerId, web::Json<api::SellParams>)| {
match *player {
0 => db_call(pool, Q::SellItems(*player, data.into_inner().items)),
_ => db_call(pool, Q::SellGroupItems(*player, data.into_inner())),
}
},
)),
),