fixes Vue reactivity problems, updates REST Api endpoints
This commit is contained in:
Binary file not shown.
@@ -1,19 +1,23 @@
|
||||
import Vue from 'vue'
|
||||
|
||||
const API_BASEURL = "http://localhost:8088/api/"
|
||||
const API_ENDPOINT = function (tailString) {
|
||||
return API_BASEURL + tailString;
|
||||
}
|
||||
|
||||
export const Api = {
|
||||
const Api = {
|
||||
fetchPlayerList () {
|
||||
return fetch("http://localhost:8088/players")
|
||||
return fetch(API_ENDPOINT("players"))
|
||||
.then(r => r.json())
|
||||
.catch(e => console.error("Fetch error ", e));
|
||||
},
|
||||
fetchClaims () {
|
||||
return fetch("http://localhost:8088/claims")
|
||||
return fetch(API_ENDPOINT("claims"))
|
||||
.then(r => r.json())
|
||||
.catch(e => console.error("Fetch error ", e));
|
||||
},
|
||||
fetchLoot (playerId) {
|
||||
const url = "http://localhost:8088/loot/" + playerId;
|
||||
return fetch(url)
|
||||
return fetch(API_ENDPOINT(playerId + "/loot"))
|
||||
.then(r => r.json())
|
||||
.catch(e => console.error("Fetch error", e));
|
||||
},
|
||||
@@ -26,7 +30,7 @@ export const Api = {
|
||||
return Promise.resolve(true);
|
||||
},
|
||||
updateWealth (playerId, goldValue) {
|
||||
return fetch("http://localhost:8088/update-wealth/" + playerId + "/" + goldValue)
|
||||
return fetch(API_ENDPOINT(playerId + "/update-wealth/" + goldValue))
|
||||
.then(r => r.json())
|
||||
.catch(e => console.error("Fetch error", e));
|
||||
}
|
||||
@@ -61,9 +65,9 @@ export const AppStorage = {
|
||||
var playerDesc = data[idx];
|
||||
const playerId = Number(playerDesc.id);
|
||||
if (this.debug) console.log("Creates", playerId, playerDesc.name)
|
||||
this.state.player_list[playerId] = playerDesc;
|
||||
this.state.player_loot[playerId] = [];
|
||||
this.state.requests[playerId] = [];
|
||||
Vue.set(this.state.player_list, playerId, playerDesc);
|
||||
Vue.set(this.state.player_loot, playerId, []);
|
||||
Vue.set(this.state.requests, playerId, []);
|
||||
}
|
||||
// Hack for now !!
|
||||
// Fetch all players loot and wait to set initiated to true
|
||||
@@ -92,6 +96,9 @@ export const AppStorage = {
|
||||
switchPlayerChestVisibility () {
|
||||
if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest)
|
||||
this.state.show_player_chest = !this.state.show_player_chest
|
||||
},
|
||||
getPlayerLoot (playerId) {
|
||||
|
||||
},
|
||||
updatePlayerWealth (goldValue) {
|
||||
if (this.debug) console.log('updatePlayerWealth', goldValue, this.state.player_id)
|
||||
|
||||
@@ -64,29 +64,29 @@ pub(crate) fn serve() -> std::io::Result<()> {
|
||||
.max_age(3600)
|
||||
)
|
||||
.route(
|
||||
"/players",
|
||||
"/api/players",
|
||||
web::get().to_async(move |pool: AppPool| {
|
||||
db_call(pool, move |api| api.fetch_players())
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/claims",
|
||||
"/api/claims",
|
||||
web::get().to_async(move |pool: AppPool| db_call(pool, move |api| api.fetch_claims())),
|
||||
)
|
||||
.route(
|
||||
"/update-wealth/{player_id}/{amount}",
|
||||
"/api/{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(
|
||||
"/loot/{player_id}",
|
||||
"/api/{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())
|
||||
}),
|
||||
)
|
||||
.route(
|
||||
"/admin/add-player/{name}/{wealth}",
|
||||
"/api/admin/add-player/{name}/{wealth}",
|
||||
web::get().to_async(move |pool: AppPool, data: web::Path<(String, f32)>| {
|
||||
db_call(pool, move |api| api.as_admin().add_player(data.0.clone(), data.1))
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user