small fixes, cleans up API
This commit is contained in:
@@ -55,6 +55,18 @@ struct PlayerClaim {
|
||||
item_id: i32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct WealthUpdate {
|
||||
player_id: i32,
|
||||
value_in_gp: f32,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Debug)]
|
||||
struct NewPlayer {
|
||||
name: String,
|
||||
wealth: 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);
|
||||
@@ -71,11 +83,29 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
||||
)
|
||||
.service(
|
||||
web::scope("/api")
|
||||
.route(
|
||||
"/players",
|
||||
web::get().to_async(move |pool: AppPool| {
|
||||
db_call(pool, move |api| api.fetch_players())
|
||||
}),
|
||||
.service(
|
||||
web::scope("/players")
|
||||
.route(
|
||||
"/all",
|
||||
web::get().to_async(move |pool: AppPool| {
|
||||
db_call(pool, move |api| api
|
||||
.fetch_players())
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/loot/{player_id}",
|
||||
web::get().to_async(move |pool: AppPool, player_id: web::Path<i32>| {
|
||||
db_call(pool, move |api| api.as_player(*player_id).loot())
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/update-wealth",
|
||||
web::put().to_async(move |pool: AppPool, data: web::Json<WealthUpdate>| {
|
||||
db_call(pool, move |api| api
|
||||
.as_player(data.player_id)
|
||||
.update_wealth(data.value_in_gp))
|
||||
})
|
||||
)
|
||||
)
|
||||
.service(
|
||||
web::resource("/claims")
|
||||
@@ -97,18 +127,6 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
||||
.unclaim(data.item_id))
|
||||
}))
|
||||
)
|
||||
.route(
|
||||
"/{player_id}/update-wealth/{amount}",
|
||||
web::get().to_async(move |pool: AppPool, data: web::Path<(i32, f32)>| {
|
||||
db_call(pool, move |api| api.as_player(data.0).update_wealth(data.1))
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/{player_id}/loot",
|
||||
web::get().to_async(move |pool: AppPool, player_id: web::Path<i32>| {
|
||||
db_call(pool, move |api| api.as_player(*player_id).loot())
|
||||
}),
|
||||
)
|
||||
.service(web::scope("/admin")
|
||||
.route(
|
||||
"/resolve-claims",
|
||||
@@ -117,12 +135,13 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/add-player/{name}/{wealth}",
|
||||
"/add-player",
|
||||
web::get().to_async(
|
||||
move |pool: AppPool, data: web::Path<(String, f32)>| {
|
||||
db_call(pool, move |api| {
|
||||
api.as_admin().add_player(&data.0, data.1)
|
||||
})
|
||||
move |pool: AppPool, data: web::Json<NewPlayer>| {
|
||||
db_call(pool, move |api| api
|
||||
.as_admin()
|
||||
.add_player(&data.name, data.wealth)
|
||||
)
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user