small fixes, cleans up API
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<PlayerView :id="state.player_id"
|
||||
v-slot="{ player, loot, notifications, actions }">
|
||||
<main id="app" class="container">
|
||||
<header class="section">
|
||||
<header style="padding-bottom: 1.5em;">
|
||||
<HeaderBar :app_state="state">
|
||||
<template v-slot:title>{{ player.name }}</template>
|
||||
<template v-slot:links>
|
||||
@@ -21,12 +21,12 @@
|
||||
{{ p.name }}</a>
|
||||
</template>
|
||||
</HeaderBar>
|
||||
<p v-show="notifications.length > 0">{{ notifications }}</p>
|
||||
<Wealth
|
||||
:wealth="[player.cp, player.sp, player.gp, player.pp]"
|
||||
:debt="player.debt"
|
||||
@update="actions.updateWealth">
|
||||
</wealth>
|
||||
</Wealth>
|
||||
<p v-show="notifications.length > 0">{{ notifications }}</p>
|
||||
</header>
|
||||
<nav>
|
||||
<div class="tabs is-centered is-boxed is-medium">
|
||||
@@ -44,7 +44,7 @@
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
<main class="">
|
||||
<main class="section">
|
||||
<template v-if="isAdding">
|
||||
<h2 v-show="playerIsGroup">ItemInput</h2>
|
||||
<AddingChest
|
||||
|
||||
@@ -6,8 +6,19 @@ const API_ENDPOINT = function (tailString) {
|
||||
}
|
||||
|
||||
export const Api = {
|
||||
__doFetch (endpoint, method, payload) {
|
||||
return fetch(API_ENDPOINT(endpoint),
|
||||
{
|
||||
method,
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(r => r.json())
|
||||
},
|
||||
fetchPlayerList () {
|
||||
return fetch(API_ENDPOINT("players"))
|
||||
return fetch(API_ENDPOINT("players/all"))
|
||||
.then(r => r.json())
|
||||
},
|
||||
fetchClaims () {
|
||||
@@ -15,36 +26,20 @@ export const Api = {
|
||||
.then(r => r.json())
|
||||
},
|
||||
fetchLoot (playerId) {
|
||||
return fetch(API_ENDPOINT(playerId + "/loot"))
|
||||
return fetch(API_ENDPOINT("players/loot/" + playerId))
|
||||
.then(r => r.json())
|
||||
},
|
||||
putClaim (player_id, item_id) {
|
||||
const payload = { player_id, item_id };
|
||||
return fetch(API_ENDPOINT("claims"),
|
||||
{
|
||||
method: 'PUT',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(r => r.json())
|
||||
return this.__doFetch("claims", 'PUT', payload);
|
||||
},
|
||||
unClaim (player_id, item_id) {
|
||||
const payload = { player_id, item_id };
|
||||
return fetch(API_ENDPOINT("claims"),
|
||||
{
|
||||
method: 'DELETE',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify(payload)
|
||||
})
|
||||
.then(r => r.json())
|
||||
return this.__doFetch("claims", 'DELETE', payload);
|
||||
},
|
||||
updateWealth (playerId, goldValue) {
|
||||
return fetch(API_ENDPOINT(playerId + "/update-wealth/" + goldValue))
|
||||
.then(r => r.json())
|
||||
updateWealth (player_id, value_in_gp) {
|
||||
const payload = { player_id, value_in_gp: Number(value_in_gp) };
|
||||
return this.__doFetch("players/update-wealth", 'PUT', payload);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -2,24 +2,35 @@
|
||||
<nav class="navbar is-info">
|
||||
<div class="navbar-brand">
|
||||
<p class="navbar-item is-size-4"><slot name="title">...</slot></p>
|
||||
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false">
|
||||
<a role="button" class="navbar-burger" aria-label="menu" aria-expanded="false"
|
||||
@click="switchMobileVisibility">
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
<span aria-hidden="true"></span>
|
||||
</a>
|
||||
</div>
|
||||
<div id="menu" class="navbar-menu">
|
||||
<div id="menu" class="navbar-menu" :class="{'is-active': showOnMobile }">
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item has-dropdown is-hoverable">
|
||||
<a class="navbar-link">Autres</a>
|
||||
<div class="navbar-dropdown is-right">
|
||||
<div class="navbar-dropdown is-right" @click="switchMobileVisibility">
|
||||
<slot name="links">
|
||||
<a class="navbar-item">History of Loot</a>
|
||||
</slot>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
data () { return { showOnMobile: false } },
|
||||
methods: {
|
||||
switchMobileVisibility () {
|
||||
this.showOnMobile = !this.showOnMobile
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
<section class="level is-mobile">
|
||||
<div class="level-left">
|
||||
<div class="level-item">
|
||||
<span class="icon is-large" @click="edit = !edit">
|
||||
<span class="icon is-large" @click="editing = !editing">
|
||||
<i class="fas fa-2x fa-piggy-bank"></i>
|
||||
</span>
|
||||
</div>
|
||||
<template v-if="edit">
|
||||
<template v-if="editing">
|
||||
<div class="level-item">
|
||||
<div class="field has-addons">
|
||||
<p class="control">
|
||||
@@ -56,7 +56,7 @@
|
||||
props: ["wealth", "debt"],
|
||||
data () {
|
||||
return {
|
||||
edit: false,
|
||||
editing: false,
|
||||
edit_value: 0,
|
||||
};
|
||||
},
|
||||
@@ -66,9 +66,13 @@
|
||||
this.resetValues();
|
||||
},
|
||||
resetValues () {
|
||||
this.edit = false;
|
||||
this.editing = false;
|
||||
this.edit_value = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.input { max-width: 9em; }
|
||||
</style>
|
||||
|
||||
@@ -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