From b4692a7a4e5f8903d42904e5ef0ca5657603fa15 Mon Sep 17 00:00:00 2001 From: Artus Date: Fri, 5 Jul 2019 14:18:12 +0200 Subject: [PATCH] fixes Vue reactivity problems, updates REST Api endpoints --- lootalot_db/db.sqlite3 | Bin 28672 -> 28672 bytes lootalot_front/src/AppStorage.js | 25 ++++++++++++++++--------- src/server.rs | 10 +++++----- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/lootalot_db/db.sqlite3 b/lootalot_db/db.sqlite3 index 5f85b4634ec27f85bc757e2378b6c53470f788a1..d0944f8e4b1657c33216fbb00d876007a8a6eef8 100644 GIT binary patch delta 84 zcmZp8z}WDBae_3X+C&*=MzxIz3;lWd-!U-r?_l6R&A)^H?q)%SRs6z&j2sM-92|^{ dj6V6fnfZCFs(h1A$14jlFff2H5?Ev)007z*5|97@ delta 77 zcmZp8z}WDBae_3X%0wAwMwN{T3;lT+7#NuOPc!hJ=6}b3ce9|vMt&Yepco8HJ{_+t aB*4hQAj!eO$jIT7pPQMV$Evi*KmY&})e+nP diff --git a/lootalot_front/src/AppStorage.js b/lootalot_front/src/AppStorage.js index 9651017..c465dbd 100644 --- a/lootalot_front/src/AppStorage.js +++ b/lootalot_front/src/AppStorage.js @@ -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) diff --git a/src/server.rs b/src/server.rs index d9aefdc..0634b37 100644 --- a/src/server.rs +++ b/src/server.rs @@ -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| { 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)) }),