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 () {
|
fetchPlayerList () {
|
||||||
return fetch("http://localhost:8088/players")
|
return fetch(API_ENDPOINT("players"))
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.catch(e => console.error("Fetch error ", e));
|
.catch(e => console.error("Fetch error ", e));
|
||||||
},
|
},
|
||||||
fetchClaims () {
|
fetchClaims () {
|
||||||
return fetch("http://localhost:8088/claims")
|
return fetch(API_ENDPOINT("claims"))
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.catch(e => console.error("Fetch error ", e));
|
.catch(e => console.error("Fetch error ", e));
|
||||||
},
|
},
|
||||||
fetchLoot (playerId) {
|
fetchLoot (playerId) {
|
||||||
const url = "http://localhost:8088/loot/" + playerId;
|
return fetch(API_ENDPOINT(playerId + "/loot"))
|
||||||
return fetch(url)
|
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.catch(e => console.error("Fetch error", e));
|
.catch(e => console.error("Fetch error", e));
|
||||||
},
|
},
|
||||||
@@ -26,7 +30,7 @@ export const Api = {
|
|||||||
return Promise.resolve(true);
|
return Promise.resolve(true);
|
||||||
},
|
},
|
||||||
updateWealth (playerId, goldValue) {
|
updateWealth (playerId, goldValue) {
|
||||||
return fetch("http://localhost:8088/update-wealth/" + playerId + "/" + goldValue)
|
return fetch(API_ENDPOINT(playerId + "/update-wealth/" + goldValue))
|
||||||
.then(r => r.json())
|
.then(r => r.json())
|
||||||
.catch(e => console.error("Fetch error", e));
|
.catch(e => console.error("Fetch error", e));
|
||||||
}
|
}
|
||||||
@@ -61,9 +65,9 @@ export const AppStorage = {
|
|||||||
var playerDesc = data[idx];
|
var playerDesc = data[idx];
|
||||||
const playerId = Number(playerDesc.id);
|
const playerId = Number(playerDesc.id);
|
||||||
if (this.debug) console.log("Creates", playerId, playerDesc.name)
|
if (this.debug) console.log("Creates", playerId, playerDesc.name)
|
||||||
this.state.player_list[playerId] = playerDesc;
|
Vue.set(this.state.player_list, playerId, playerDesc);
|
||||||
this.state.player_loot[playerId] = [];
|
Vue.set(this.state.player_loot, playerId, []);
|
||||||
this.state.requests[playerId] = [];
|
Vue.set(this.state.requests, playerId, []);
|
||||||
}
|
}
|
||||||
// Hack for now !!
|
// Hack for now !!
|
||||||
// Fetch all players loot and wait to set initiated to true
|
// Fetch all players loot and wait to set initiated to true
|
||||||
@@ -92,6 +96,9 @@ export const AppStorage = {
|
|||||||
switchPlayerChestVisibility () {
|
switchPlayerChestVisibility () {
|
||||||
if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest)
|
if (this.debug) console.log('switchPlayerChestVisibility', !this.state.show_player_chest)
|
||||||
this.state.show_player_chest = !this.state.show_player_chest
|
this.state.show_player_chest = !this.state.show_player_chest
|
||||||
|
},
|
||||||
|
getPlayerLoot (playerId) {
|
||||||
|
|
||||||
},
|
},
|
||||||
updatePlayerWealth (goldValue) {
|
updatePlayerWealth (goldValue) {
|
||||||
if (this.debug) console.log('updatePlayerWealth', goldValue, this.state.player_id)
|
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)
|
.max_age(3600)
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/players",
|
"/api/players",
|
||||||
web::get().to_async(move |pool: AppPool| {
|
web::get().to_async(move |pool: AppPool| {
|
||||||
db_call(pool, move |api| api.fetch_players())
|
db_call(pool, move |api| api.fetch_players())
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/claims",
|
"/api/claims",
|
||||||
web::get().to_async(move |pool: AppPool| db_call(pool, move |api| api.fetch_claims())),
|
web::get().to_async(move |pool: AppPool| db_call(pool, move |api| api.fetch_claims())),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/update-wealth/{player_id}/{amount}",
|
"/api/{player_id}/update-wealth/{amount}",
|
||||||
web::get().to_async(move |pool: AppPool, data: web::Path<(i32, f32)>| {
|
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))
|
db_call(pool, move |api| api.as_player(data.0).update_wealth(data.1))
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/loot/{player_id}",
|
"/api/{player_id}/loot",
|
||||||
web::get().to_async(move |pool: AppPool, player_id: web::Path<i32>| {
|
web::get().to_async(move |pool: AppPool, player_id: web::Path<i32>| {
|
||||||
db_call(pool, move |api| api.as_player(*player_id).loot())
|
db_call(pool, move |api| api.as_player(*player_id).loot())
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.route(
|
.route(
|
||||||
"/admin/add-player/{name}/{wealth}",
|
"/api/admin/add-player/{name}/{wealth}",
|
||||||
web::get().to_async(move |pool: AppPool, data: web::Path<(String, f32)>| {
|
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))
|
db_call(pool, move |api| api.as_admin().add_player(data.0.clone(), data.1))
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user