From 9816cdf488112e23f8d8f19cb050ba04f94d2844 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Mon, 29 Apr 2019 17:35:50 +0200 Subject: [PATCH 01/25] Some changes --- frontend/quasar.conf.js | 2 +- frontend/src/pages/CacheStart.vue | 3 +- frontend/src/pages/Register.vue | 4 +- frontend/src/pages/StationView.vue | 3 +- .../bugageocaching/controller/Controller.java | 180 +++++++++--------- .../bugageocaching/entities/User_Info.java | 4 + .../repositories/User_InfoRepository.java | 10 +- .../labsw/bugageocaching/util/FinderUtil.java | 12 +- 8 files changed, 118 insertions(+), 100 deletions(-) diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index 1ceac6e..13253ee 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -109,7 +109,7 @@ module.exports = function (ctx) { API: JSON.stringify('http://localhost:8080') } : { // Base URL for API-Calls: PRODUCTION (build) - //API: JSON.stringify('http://seserver.se.hs-heilbronn.de:8090/buga19geocaching') + //API: JSON.stringify('http://seserver.se.hs-heilbronn.de:9080/buga19geocaching') API: JSON.stringify('http://localhost:8080') } }, diff --git a/frontend/src/pages/CacheStart.vue b/frontend/src/pages/CacheStart.vue index 2cc51de..d1b4466 100644 --- a/frontend/src/pages/CacheStart.vue +++ b/frontend/src/pages/CacheStart.vue @@ -97,7 +97,8 @@ params.cacheID = this.result.split('/')[0]; params.stationID = this.result.split('/')[1]; params.durchgefuehrterCacheID = this.cacheID; - console.log(params.cacheID + " und " + params.stationID); + console.log("CacheID: " + params.cacheID + " und StationID: " + params.stationID); + console.log(params.durchgefuehrterCacheID); if (localStorage.getItem('userToken')) { params.token = JSON.parse(localStorage.getItem('userToken')).token; } diff --git a/frontend/src/pages/Register.vue b/frontend/src/pages/Register.vue index 6a80aa9..318552a 100644 --- a/frontend/src/pages/Register.vue +++ b/frontend/src/pages/Register.vue @@ -110,7 +110,7 @@ console.log("POST /api/register/ - json: " + JSON.stringify(data)); const token = JSON.parse(localStorage.getItem('registerToken')).token; - this.$axios.post('http://www.se.hs-heilbronn.de:8090/buga19usermanagement/account/register', data,{ + this.$axios.post('http://www.se.hs-heilbronn.de:9080/buga19usermanagement/account/register', data,{ headers: { 'Authorization': 'Bearer ' + token, } @@ -167,7 +167,7 @@ console.log("GET /api/login/ - json: " + JSON.stringify(logindata)); - this.$axios.post('http://www.se.hs-heilbronn.de:8090/buga19usermanagement/account/login', logindata) + this.$axios.post('http://www.se.hs-heilbronn.de:9080/buga19usermanagement/account/login', logindata) .then((response) => { localStorage.setItem('registerToken', JSON.stringify(response.data)); }) diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index 453ffb8..8696cf7 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -167,7 +167,8 @@ let params = {}; params.cacheID = this.result.split('/')[0]; params.stationID = this.result.split('/')[1]; - params.durchgefuehrterCacheID = this.cacheID; + params.durchgefuehrterCacheID = params.cacheID; + console.log(params.durchgefuehrterCacheID); console.log(params.cacheID + " und " + params.stationID); if (localStorage.getItem('userToken')) { params.token = JSON.parse(localStorage.getItem('userToken')).token; diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 881f78c..6504a54 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -16,7 +16,6 @@ import javax.annotation.PostConstruct; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import java.util.Optional; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.createCacheUtil; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.deleteCacheUtil; @@ -61,88 +60,88 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll())); } - // alte startCache-methode -// @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose -// @RequestMapping("/api/startCache") -// @ResponseBody -// public ResponseEntity startCache(@RequestParam(value = "token", defaultValue = "-1") String token, -// @RequestParam String cacheID) { -// -// if (!token.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben) -// -// Bearbeitet bearbeitet = new Bearbeitet(); -// -// -// //---------------------- -// //Verify token -// ResponseEntity tokenVerification = VerificationUtil.verifyToken(token); -// -// //Error in token verification -// if (tokenVerification.getStatusCodeValue() != 200) { -// return tokenVerification; -// } -// -// Claims claims = (Claims) tokenVerification.getBody(); -// -// ResponseEntity getUser = FinderUtil.findUserFromClaim(claims); -// -// if (getUser.getStatusCodeValue() != 200) { -// return getUser; -// } -// -// User user = (User) getUser.getBody(); -// -// bearbeitet.setUser(user); -// -// //---------------------- -// //Get Cache -// ResponseEntity getCache = FinderUtil.findCacheById(cacheID); -// -// if (getCache.getStatusCodeValue() != 200) { -// return getCache; -// } -// -// Cache cache = (Cache) getCache.getBody(); -// //---------------------- -// -// if (bearbeitetRepository.findByUserAndCache(user, cache) != null) { -// Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache); -// return ResponseEntity.status(200).body(bearbeitet1); -// } -// -// bearbeitet.setCache(cache); -// -// Station startStation = cache.getStationen().get(0); -// bearbeitet.setAktuelleStation(startStation); -// -// //Get CacheAccesDefinition -// ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0"); -// -// if (getCacheAccesDefinition.getStatusCodeValue() != 200) { -// return getCacheAccesDefinition; -// } -// -// CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody(); -// //---------------------- -// bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); -// -// bearbeitetRepository.save(bearbeitet); -// -// return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet)); -// -// } else { // kein angemeldeter User startet den cache(es wird nur der cache als parameter übergeben) -// -// ResponseEntity getCache = FinderUtil.findCacheById(cacheID); -// -// if (getCache.getStatusCodeValue() != 200) { -// return getCache; -// } -// -// Cache cache = (Cache) getCache.getBody(); -// -// return ResponseEntity.status(200).body(new Gson().toJson(cache)); -// } -// } + + @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose + @RequestMapping("/api/startCache") + @ResponseBody + public ResponseEntity startCache(@RequestParam(value = "token", defaultValue = "-1") String token, + @RequestParam String cacheID) { + + if (!token.equals("-1")) { // ein angemeldeter user startet den cache(es werden zwei parameter übergeben) + + Bearbeitet bearbeitet = new Bearbeitet(); + + + //---------------------- + //Verify token + ResponseEntity tokenVerification = VerificationUtil.verifyToken(token); + + //Error in token verification + if (tokenVerification.getStatusCodeValue() != 200) { + return tokenVerification; + } + + Claims claims = (Claims) tokenVerification.getBody(); + + ResponseEntity getUser = FinderUtil.findUserFromClaim(claims); + + if (getUser.getStatusCodeValue() != 200) { + return getUser; + } + + User user = (User) getUser.getBody(); + + bearbeitet.setUser(user); + + //---------------------- + //Get Cache + ResponseEntity getCache = FinderUtil.findCacheById(cacheID); + + if (getCache.getStatusCodeValue() != 200) { + return getCache; + } + + Cache cache = (Cache) getCache.getBody(); + //---------------------- + + if (bearbeitetRepository.findByUserAndCache(user, cache) != null) { + Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache); + return ResponseEntity.status(200).body(bearbeitet1); + } + + bearbeitet.setCache(cache); + + Station startStation = cache.getStationen().get(0); + bearbeitet.setAktuelleStation(startStation); + + //Get CacheAccesDefinition + ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("0"); + + if (getCacheAccesDefinition.getStatusCodeValue() != 200) { + return getCacheAccesDefinition; + } + + CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody(); + //---------------------- + bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); + + //bearbeitetRepository.save(bearbeitet); + + return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet)); + + } else { // kein angemeldeter User startet den cache(es wird nur der cache als parameter übergeben) + + ResponseEntity getCache = FinderUtil.findCacheById(cacheID); + + if (getCache.getStatusCodeValue() != 200) { + return getCache; + } + + Cache cache = (Cache) getCache.getBody(); + + return ResponseEntity.status(200).body(new Gson().toJson(cache)); + } + } @CrossOrigin(origins = "http://localhost:8081") // only for dev purpose @RequestMapping("/api/checkStation") @@ -205,8 +204,11 @@ public class Controller { Station station = (Station) getStation.getBody(); //---------------------- - if (cache != durchgefuehrterCache) { - return ResponseEntity.status(400).body("The scanned station isn´t the correct following station"); + System.out.println(cache.getName()); + System.out.println(durchgefuehrterCache.getName()); + + if (!cacheID.equals(durchgefuehrterCacheID)) { + return ResponseEntity.status(400).body("The scanned station isn´t the correct following station (Name)"); } if (!cache.getStationen().contains(station)) { @@ -220,6 +222,7 @@ public class Controller { if (getBearbeitet.getStatusCodeValue() != 200) { if (cache.getStationen().get(0).equals(station)) { // start Cache + System.out.println("Startstation"); Bearbeitet bearbeitet = new Bearbeitet(); bearbeitet.setUser(user); bearbeitet.setCache(cache); @@ -256,7 +259,7 @@ public class Controller { int i = cache.getStationen().indexOf(station); if (i == 0) { - return ResponseEntity.status(400).body("The scanned station isn´t the correct following station"); + return ResponseEntity.status(400).body("The scanned station isn´t the correct following station (i==0)"); } if (cache.getStationen().get(i - 1).equals(aktuelleStation)) { @@ -274,6 +277,7 @@ public class Controller { //---------------------- bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); //Get User_Info + System.out.println(String.valueOf(user.getId())); ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId())); if (getUser_Info.getStatusCodeValue() != 200) { @@ -282,13 +286,13 @@ public class Controller { User_Info user_info = (User_Info) getUser_Info.getBody(); //---------------------- - user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints()); + //user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints()); user_infoRepository.save(user_info); } bearbeitetRepository.save(bearbeitet); return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet)); } else { - return ResponseEntity.status(400).body("The scanned station isn´t the correct following station"); + return ResponseEntity.status(400).body("The scanned station isn´t the correct following station(nicht letzte)"); } } diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java b/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java index 74ff0a3..4aa135a 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java @@ -2,6 +2,7 @@ package hhn.labsw.bugageocaching.entities; import org.springframework.context.annotation.Primary; +import javax.annotation.Generated; import javax.persistence.*; import java.io.Serializable; @@ -15,6 +16,8 @@ public class User_Info implements Serializable { private User user; @Id + private int id; + private int rankingPointsSum; @ManyToOne @@ -47,4 +50,5 @@ public class User_Info implements Serializable { public void setTeam(Team team) { this.team = team; } + } diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java index a96b12d..06917b0 100644 --- a/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java +++ b/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java @@ -1,8 +1,16 @@ package hhn.labsw.bugageocaching.repositories; +import hhn.labsw.bugageocaching.entities.User; import hhn.labsw.bugageocaching.entities.User_Info; +import org.springframework.data.jpa.repository.Query; import org.springframework.data.repository.CrudRepository; -public interface User_InfoRepository extends CrudRepository { +import java.util.List; +import java.util.Optional; +public interface User_InfoRepository extends CrudRepository { + User_Info findByUser(User user); + + @Query(value = "SELECT * FROM user_info WHERE user_id = ?1", nativeQuery = true) + User_Info findUser_InfoByUserId(int UserId); } diff --git a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java index 4b4c595..0c4312f 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java @@ -10,6 +10,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Component; +import java.util.List; import java.util.Optional; @Component @@ -124,12 +125,11 @@ public class FinderUtil { } public static ResponseEntity findUser_InfoByID(String infoID) { - Optional user_InfoOptional = user_infoRepository.findById(Integer.valueOf(infoID)); - if (user_InfoOptional.isPresent()) { - return ResponseEntity.status(200).body(user_InfoOptional.get()); - } else { - return ResponseEntity.status(404).body("Couldnt find User_Info " + infoID); - } + User_Info user_info = user_infoRepository.findUser_InfoByUserId(Integer.valueOf(infoID)); + + + + return ResponseEntity.status(200).body(user_info); } public static ResponseEntity findUserFromClaim(Claims claims) { From 65d3e77558fc52b10ac8cca94466178d6d638e09 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 29 Apr 2019 20:37:30 +0200 Subject: [PATCH 02/25] fixed some bugs and created data-store for current cache --- frontend/src/layouts/MyLayout.vue | 29 ++++++++------- frontend/src/pages/Login.vue | 12 +++---- frontend/src/pages/Overview.vue | 49 ++++++-------------------- frontend/src/pages/Profile.vue | 8 +++-- frontend/src/pages/StationView.vue | 2 +- frontend/src/store/dialog/mutations.js | 8 ++--- frontend/src/store/index.js | 12 +++++-- 7 files changed, 54 insertions(+), 66 deletions(-) diff --git a/frontend/src/layouts/MyLayout.vue b/frontend/src/layouts/MyLayout.vue index a2a51d5..7054c59 100644 --- a/frontend/src/layouts/MyLayout.vue +++ b/frontend/src/layouts/MyLayout.vue @@ -86,6 +86,7 @@ - + - Login + Registrieren - + - Register + {{ loginText }} @@ -172,37 +173,41 @@ }; }, computed: { + loginText() { + let text = this.$store.state.auth.isAuthenticated ? "Logout" : "Login"; + return text; + }, dialogShow: { get() { - console.log("get dialogShow: "+this.$store.state.dialog.dialog.show) + // console.log("get dialogShow: "+this.$store.state.dialog.dialog.show) return this.$store.state.dialog.dialog.show; }, set(val) { - console.log("set dialogShow: "+val) + // console.log("set dialogShow: "+val) this.$store.state.dialog.dialog.show = val; } }, dialogMessage: { get() { - console.log("get dialogMessage: "+this.$store.state.dialog.dialog.message) + // console.log("get dialogMessage: "+this.$store.state.dialog.dialog.message) return this.$store.state.dialog.dialog.message; }, }, dialogTitle: { get() { - console.log("get dialogTitle: "+this.$store.state.dialog.dialog.title) + // console.log("get dialogTitle: "+this.$store.state.dialog.dialog.title) return this.$store.state.dialog.dialog.title; }, }, dialogColorBg: { get() { - console.log("get dialogColorBg: " + this.$store.state.dialog.dialog.colorBackground) + // console.log("get dialogColorBg: " + this.$store.state.dialog.dialog.colorBackground) return this.$store.state.dialog.dialog.colorBackground; }, }, dialogColorBtn: { get() { - console.log("get dialogColorBtn: "+this.$store.state.dialog.dialog.colorButton) + // console.log("get dialogColorBtn: "+this.$store.state.dialog.dialog.colorButton) return this.$store.state.dialog.dialog.colorButton; }, } diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 881b3d7..21376da 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -23,9 +23,9 @@
{ let message; let header = "Fehler: "; if (error.response) { - console.log("ERROR RESPONSE") + console.log("ERROR RESPONSE"); // The request was made and the server responded with a status code // that falls out of the range of 2xx message = error.response.data.error; @@ -128,6 +127,7 @@ this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: message, title: header, }); }).finally(() => { this.loading = false; + this.evalAuthentication(); }) }, evalAuthentication: function () { diff --git a/frontend/src/pages/Overview.vue b/frontend/src/pages/Overview.vue index ee39fe9..20dc7e7 100644 --- a/frontend/src/pages/Overview.vue +++ b/frontend/src/pages/Overview.vue @@ -26,7 +26,6 @@ { - console.log(response.data); - // TODO wenn cache angefangen, dann suche die letzte gefundene Station - let stationID = this.caches.find(x => x.id === cacheID).stationen[0].id; - console.log(stationID); - //this.$router.push({path: `/station/${stationID}`}) - this.$router.push({path: `/CacheStart/${cacheID}`}) - }).catch((error) => { - // Error - let msg; - let title; - if (error.response) { - // The request was made and the server responded with a status code - title = "Problem with response!"; - msg = error.response; - } else if (error.request) { - // The request was made but no response was received - title = "Problem with request!"; - msg = "Error occured due to wrong server request!" - console.log(error.request); - } else { - // Something happened in setting up the request that triggered an Error - title = "Error"; - msg = error.message; - console.log('Error', error.message); - } - console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); - }) + console.log("startCache()"); + // const userToken = JSON.parse(localStorage.getItem('userToken')).token; + // let params = {cacheID: cacheID}; + // if (userToken != null) { + // params.token = userToken; + // } + // console.log(params); + this.$store.state.currentCache.cache = this.caches.find(cache => cache.id === Number(cacheID)); + console.log(this.$store.state.currentCache.cache); + this.$store.state.currentCache.currentCacheID = Number(cacheID); + this.$router.push({path: `/CacheStart/${cacheID}`}) } } } diff --git a/frontend/src/pages/Profile.vue b/frontend/src/pages/Profile.vue index 810a559..8fe3df2 100644 --- a/frontend/src/pages/Profile.vue +++ b/frontend/src/pages/Profile.vue @@ -267,7 +267,11 @@ }, methods: { fetchUserCaches: function () { - const token = JSON.parse(localStorage.getItem('userToken')).token; + if (localStorage.getItem('userToken')) { + const token = JSON.parse(localStorage.getItem('userToken')).token; + } else { + return; + } this.$axios.get('/api/getMyCaches', {params: {token}}) .then((response) => { this.startedCaches = response.data; @@ -297,7 +301,7 @@ continueCache(cacheID) { }, validateEmail(email) { - var re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; + let re = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/; return re.test(String(email).toLowerCase()); }, } diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index 453ffb8..1a19b9c 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -80,7 +80,7 @@ } }, created: function () { - console.log("StationView: ") + console.log("StationView: "); // console.log("'id' from url: " + this.$route.params.id) // console.log("'cache' from url: " + this.$route.params.cache) this.fetchData(); diff --git a/frontend/src/store/dialog/mutations.js b/frontend/src/store/dialog/mutations.js index 8994399..4a14ffa 100644 --- a/frontend/src/store/dialog/mutations.js +++ b/frontend/src/store/dialog/mutations.js @@ -1,12 +1,12 @@ export function NEW_MESSAGE_DIALOG (state, messageObject) { - console.log("NEW_MESSAGE_DIALOG"); - console.log(messageObject); + // console.log("NEW_MESSAGE_DIALOG"); + // console.log(messageObject); if (messageObject == null) { state.dialog.show = true; return; } - console.log(messageObject); + // console.log(messageObject); if (messageObject.hasOwnProperty('color')) { switch (messageObject.color) { @@ -39,7 +39,7 @@ export function NEW_MESSAGE_DIALOG (state, messageObject) { state.dialog.show = true; } export function RESET_MESSAGE_DIALOG (state) { - console.log("RESET_MESSAGE_DIALOG"); + // console.log("RESET_MESSAGE_DIALOG"); state.dialog.colorBackground = "bg-red-9 text-white"; state.dialog.colorButton = "red-9"; state.dialog.message = "Ein unbekannter Fehler ist aufgetreten. Bitte versuchen Sie es noch einmal."; diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 58a40f8..9a7a3b2 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -4,6 +4,7 @@ import Axios from "axios"; import auth from "./auth" import cacheCollector from "./cacheCollector" import dialog from "./dialog" +import currentCache from "./currentCache" // import example from './module-example' @@ -19,7 +20,8 @@ export default function (/* { ssrContext } */) { modules: { auth, cacheCollector, - dialog + dialog, + currentCache }, // enable strict mode (adds overhead!) @@ -42,11 +44,15 @@ export default function (/* { ssrContext } */) { module.hot.accept(['./cacheCollector'], () => { const cacheCollector = require('./cacheCollector').default; store.hotUpdate({ modules: { cacheCollector: newCacheCollector } }) - }) + }); module.hot.accept(['./dialog'], () => { const dialog = require('./dialog').default; store.hotUpdate({ modules: { dialog: newDialog } }) - }) + }); + module.hot.accept(['./currentCache'], () => { + const currentCache = require('./currentCache').default; + store.hotUpdate({ modules: { currentCache: newCurrentCache } }) + }); } return Store From e1944ff8d4ae107c0b58ba09805bfa0f6369cd2c Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 29 Apr 2019 20:51:40 +0200 Subject: [PATCH 03/25] works???? pls? --- .../bugageocaching/controller/Controller.java | 34 +++---------------- .../bugageocaching/entities/User_Info.java | 10 ++++++ .../bugageocaching/entities/User_InfoID.java | 2 +- .../repositories/User_InfoRepository.java | 5 +-- .../labsw/bugageocaching/util/FinderUtil.java | 12 ++----- 5 files changed, 19 insertions(+), 44 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 6504a54..4082012 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -278,15 +278,9 @@ public class Controller { bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); //Get User_Info System.out.println(String.valueOf(user.getId())); - ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId())); - - if (getUser_Info.getStatusCodeValue() != 200) { - return getUser_Info; - } - - User_Info user_info = (User_Info) getUser_Info.getBody(); + User_Info user_info = user_infoRepository.findUser_InfoByUser(user); //---------------------- - //user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints()); + user_info.setRankingPointsSum(user_info.getRankingPointsSum() + cache.getRankingPoints()); user_infoRepository.save(user_info); } bearbeitetRepository.save(bearbeitet); @@ -468,13 +462,7 @@ public class Controller { User user = (User) getUser.getBody(); //Get User_Info - ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId())); - - if (getUser_Info.getStatusCodeValue() != 200) { - return getUser_Info; - } - - User_Info user_info = (User_Info) getUser_Info.getBody(); + User_Info user_info = user_infoRepository.findUser_InfoByUser(user); //---------------------- if (user_info.getTeam() != null) { return ResponseEntity.status(400).body("You already have a team"); @@ -521,13 +509,7 @@ public class Controller { User user = (User) getUser.getBody(); //Get User_Info - ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId())); - - if (getUser_Info.getStatusCodeValue() != 200) { - return getUser_Info; - } - - User_Info user_info = (User_Info) getUser_Info.getBody(); + User_Info user_info = user_infoRepository.findUser_InfoByUser(user); //---------------------- if (user_info.getTeam() != null) { return ResponseEntity.status(400).body("You already have a team"); @@ -588,13 +570,7 @@ public class Controller { User user = (User) getUser.getBody(); //Get User_Info - ResponseEntity getUser_Info = FinderUtil.findUser_InfoByID(String.valueOf(user.getId())); - - if (getUser_Info.getStatusCodeValue() != 200) { - return getUser_Info; - } - - User_Info user_info = (User_Info) getUser_Info.getBody(); + User_Info user_info = user_infoRepository.findUser_InfoByUser(user); //---------------------- if (user_info.getTeam() == null) { return ResponseEntity.status(400).body("You aren´t in any team"); diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java b/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java index 4aa135a..c74c428 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/User_Info.java @@ -1,5 +1,6 @@ package hhn.labsw.bugageocaching.entities; +import org.hibernate.validator.constraints.UniqueElements; import org.springframework.context.annotation.Primary; import javax.annotation.Generated; @@ -16,6 +17,7 @@ public class User_Info implements Serializable { private User user; @Id + @GeneratedValue private int id; private int rankingPointsSum; @@ -27,6 +29,14 @@ public class User_Info implements Serializable { public User_Info() { } + public int getId() { + return id; + } + + public void setId(int id) { + this.id = id; + } + public User getUser() { return user; } diff --git a/src/main/java/hhn/labsw/bugageocaching/entities/User_InfoID.java b/src/main/java/hhn/labsw/bugageocaching/entities/User_InfoID.java index 4d63e41..2c04860 100644 --- a/src/main/java/hhn/labsw/bugageocaching/entities/User_InfoID.java +++ b/src/main/java/hhn/labsw/bugageocaching/entities/User_InfoID.java @@ -4,5 +4,5 @@ import java.io.Serializable; public class User_InfoID implements Serializable { private int user; - private int rankingPointsSum; + private int id; } diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java index 06917b0..309cc41 100644 --- a/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java +++ b/src/main/java/hhn/labsw/bugageocaching/repositories/User_InfoRepository.java @@ -9,8 +9,5 @@ import java.util.List; import java.util.Optional; public interface User_InfoRepository extends CrudRepository { - User_Info findByUser(User user); - - @Query(value = "SELECT * FROM user_info WHERE user_id = ?1", nativeQuery = true) - User_Info findUser_InfoByUserId(int UserId); + User_Info findUser_InfoByUser(User user); } diff --git a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java index 0c4312f..06fce97 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java @@ -35,7 +35,7 @@ public class FinderUtil { @Autowired public void setCacheRepository(CacheRepository cacheRepository) { - FinderUtil.cacheRepository= cacheRepository; + FinderUtil.cacheRepository = cacheRepository; } @Autowired @@ -124,14 +124,6 @@ public class FinderUtil { } } - public static ResponseEntity findUser_InfoByID(String infoID) { - User_Info user_info = user_infoRepository.findUser_InfoByUserId(Integer.valueOf(infoID)); - - - - return ResponseEntity.status(200).body(user_info); - } - public static ResponseEntity findUserFromClaim(Claims claims) { try { @@ -161,4 +153,4 @@ public class FinderUtil { } } - } +} From 33ed2e32b9489a3bf81866e59a76837fa8e2f0e8 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 29 Apr 2019 21:34:26 +0200 Subject: [PATCH 04/25] fixed cache process --- frontend/src/boot/axios.js | 2 +- frontend/src/pages/CacheStart.vue | 8 +++- frontend/src/pages/StationView.vue | 75 +++++++----------------------- frontend/src/pages/qr-scanner.vue | 35 +++++++------- 4 files changed, 43 insertions(+), 77 deletions(-) diff --git a/frontend/src/boot/axios.js b/frontend/src/boot/axios.js index ea842da..88a12cd 100644 --- a/frontend/src/boot/axios.js +++ b/frontend/src/boot/axios.js @@ -2,7 +2,7 @@ import axios from "axios"; const axiosInstance = axios.create({ baseURL: process.env.API, - timeout: 3000 + timeout: 6000 }); console.log("process.env.DEV: "+process.env.DEV); console.log("process.env.API: "+process.env.API); diff --git a/frontend/src/pages/CacheStart.vue b/frontend/src/pages/CacheStart.vue index 2cc51de..fadcfb1 100644 --- a/frontend/src/pages/CacheStart.vue +++ b/frontend/src/pages/CacheStart.vue @@ -126,8 +126,14 @@ this.$axios.get('/api/checkStation', {params}) .then((response) => { console.log("resolve(true)"); + console.log("cache access definition"); + console.log(response.data.cacheAccesDefinition); resolve(true); - this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`}); + if (Number(response.data.cacheAccesDefinition.id) === 0) { + this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`}); + } else if (Number(response.data.cacheAccesDefinition.id) === 1) { + this.$router.push({path: `/CacheEnd/${params.cacheID}`}); + } }).catch((error) => { console.log("resolve(false)"); // Error diff --git a/frontend/src/pages/StationView.vue b/frontend/src/pages/StationView.vue index 1a19b9c..450e925 100644 --- a/frontend/src/pages/StationView.vue +++ b/frontend/src/pages/StationView.vue @@ -52,6 +52,8 @@ data() { return { //code: "", + cacheID: "", + cacheName: "", cache: null, data: { cacheId: 22, @@ -91,9 +93,13 @@ }, computed: { showCacheProgress() { - let stationCount = this.cache.stationen.length; - let stationPos = 1 + this.cache.stationen.findIndex(station => station.id === Number(this.$route.params.id)); - return `${stationPos} von ${stationCount}`; + if (this.cache !== null) { + let stationCount = this.cache.stationen.length; + let stationPos = 1 + this.cache.stationen.findIndex(station => station.id === Number(this.$route.params.id)); + return `${stationPos} von ${stationCount}`; + } else { + return ""; + } } }, methods: { @@ -105,61 +111,10 @@ console.log(this.data); console.log(response.data); const cache = response.data.find(cache => cache.id === Number(this.$route.params.cache)); - this.data.cacheId = cache.id; - this.data.cacheName = cache.name; this.cache = cache; - console.log(JSON.stringify(this.data)); - this.$axios.get('/api/getAllStations') - .then((response) => { - console.log("/api/getAllStations"); - console.log(response.data); - const stationView = response.data.find(station => station.id === Number(this.$route.params.id)); - console.log(JSON.stringify(stationView)); - this.data.station = stationView; - }).catch((error) => { - // Error - let msg; - let title; - if (error.response) { - // The request was made and the server responded with a status code - title = "Problem with response!"; - msg = error.response; - } else if (error.request) { - // The request was made but no response was received - title = "Problem with request!"; - msg = "Error occured due to wrong server request!" - console.log(error.request); - } else { - // Something happened in setting up the request that triggered an Error - title = "Error"; - msg = error.message; - console.log('Error', error.message); - } - console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); - }) - }).catch((error) => { - // Error - let msg; - let title; - if (error.response) { - // The request was made and the server responded with a status code - title = "Problem with response!"; - msg = error.response; - } else if (error.request) { - // The request was made but no response was received - title = "Problem with request!"; - msg = "Error occured due to wrong server request!" - console.log(error.request); - } else { - // Something happened in setting up the request that triggered an Error - title = "Error"; - msg = error.message; - console.log('Error', error.message); - } - console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); - }) + this.cacheName = cache.name; + this.cacheID = this.$route.params.cache; + }) }, setParams() { @@ -197,10 +152,12 @@ this.$axios.get('/api/checkStation', {params}) .then((response) => { console.log("resolve(true)"); + console.log("cache access definition"); + console.log(response.data.cacheAccesDefinition); resolve(true); - if (response.data.cache_acces_definition === 0) { + if (Number(response.data.cacheAccesDefinition.id) === 0) { this.$router.push({path: `/station/${params.cacheID}/${params.stationID}`}); - } else if (response.data.cache_acces_definition === 1) { + } else if (Number(response.data.cacheAccesDefinition.id) === 1) { this.$router.push({path: `/CacheEnd/${params.cacheID}`}); } }).catch((error) => { diff --git a/frontend/src/pages/qr-scanner.vue b/frontend/src/pages/qr-scanner.vue index 087cb71..e111c73 100644 --- a/frontend/src/pages/qr-scanner.vue +++ b/frontend/src/pages/qr-scanner.vue @@ -1,6 +1,6 @@