diff --git a/lootalot_db/db.sqlite3 b/lootalot_db/db.sqlite3 index 5f85b46..d0944f8 100644 Binary files a/lootalot_db/db.sqlite3 and b/lootalot_db/db.sqlite3 differ 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)) }),