diff --git a/frontend/src/boot/axios.js b/frontend/src/boot/axios.js index 8523d48..ea842da 100644 --- a/frontend/src/boot/axios.js +++ b/frontend/src/boot/axios.js @@ -1,7 +1,8 @@ import axios from "axios"; const axiosInstance = axios.create({ - baseURL: process.env.API + baseURL: process.env.API, + timeout: 3000 }); console.log("process.env.DEV: "+process.env.DEV); console.log("process.env.API: "+process.env.API); diff --git a/frontend/src/layouts/MyLayout.vue b/frontend/src/layouts/MyLayout.vue index ab73ffc..a2a51d5 100644 --- a/frontend/src/layouts/MyLayout.vue +++ b/frontend/src/layouts/MyLayout.vue @@ -43,6 +43,20 @@ Startseite + + + + + + QR-Code Scanner + +
- - -
-
-

{{ isNewCache ? "Neuen Cache erstellen" : "Cache bearbeiten"}}

- - - - -

Stationen

- + + + +
+

{{ isNewCache ? "Neuen Cache erstellen" : "Cache bearbeiten"}}

+ + +

Beschreibung

+ +

Belohnung

+ +

Stationen

+ - - - - {{ index + 1 }} - - + + + + {{ index + 1 }} + + - - - ID: {{ station.id ? station.id : "keine" }} - - - {{ station.description }} - - - Code: {{ station.code }} - - + + + ID: {{ station.id ? station.id : "keine" }} + + + {{ station.description }} + + + Code: {{ station.code }} + + - -
- - -
-
-
+ +
+ + +
+
+
-
-
- -
-
- -
+ +
+
- - +

Endstation

+ + + + + {{ tempCache.stationen.length + 1 }} + + + + + + ID: {{ endStation.id ? endStation.id : "keine" }} + + + Endstation + + + Koordinaten: {{ endStation.lattitude }}, {{ endStation.longitude }} + + + + +
+ +
+
+
+
+
+ +
+
+ +
@@ -81,7 +114,7 @@ name: "Cache", data() { return { - // stationComponent: null, + //endStation: {}, scrolldown: false, isNewCache: this.$route.params.id === undefined, tempCache: {}, @@ -112,16 +145,20 @@ //this.scrollToBottom(); }, methods: { - // ...mapMutations([ - // 'cacheCollector/SET_CACHE', - // 'cacheCollector/ADD_STATION', - // 'cacheCollector/REMOVE_STATION', - // 'cacheCollector/RESET_NEW_CACHE', - // 'cacheCollector/LOAD_REMOTE_CACHE' - // ]), - // swapComponent: function (component) { - // this.stationComponent = component; - // }, + editEndStation() { + console.log("editEndStation()"); + const station = this.endStation; + console.log(station); + if (station.hasOwnProperty('id')) { + //this.$router.push({ path: '/station/'+station.id}); + } else { + // TODO Stationen bearbeitbar machen bevor sie abgeschickt werden. Am besten Station Objekt als Übergabe Parameter bei Router + this.$store.commit('cacheCollector/SET_TEMPSTATION', station); + //this.$router.push({path: `/tempendstation/${index}`}); // add parameter + this.$router.push({path: `/tempendstation/`}); // add parameter + } + + }, cacheToStore() { // push tempCache to Store console.log("set Cache"); @@ -129,20 +166,20 @@ // this.SET_CACHE(JSON.parse(JSON.stringify(this.tempCache))); }, addStation() { - this.$router.push({ path: '/station' }); + this.$router.push({path: '/station'}); //this.swapComponent(station); // create Station and add it to array tempCache.stationen }, editStation(index) { - console.log("editStation("+index+")"); + console.log("editStation(" + index + ")"); const station = this.cache.stationen[index]; - console.log(station) - if (station.hasOwnProperty('id') ) { + console.log(station); + if (station.hasOwnProperty('id')) { //this.$router.push({ path: '/station/'+station.id}); } else { // TODO Stationen bearbeitbar machen bevor sie abgeschickt werden. Am besten Station Objekt als Übergabe Parameter bei Router this.$store.commit('cacheCollector/SET_TEMPSTATION', station); - this.$router.push({ path: `/station-l/${index}` }); // add parameter + this.$router.push({path: `/tempstation/${index}`}); // add parameter } }, deleteStation(index) { @@ -153,12 +190,14 @@ // commit to store, send to api, if success -> reset store if (this.isNewCache) { console.log(this.cache); - console.log(JSON.stringify(this.cache)); - this.$axios.post('/api/createCache', this.cache) + let cache = this.cache; + cache.stationen.push(this.endStation); + + this.$axios.post('/api/createCache', cache) .then((response) => { console.log("POST api/createCache: " + response.statusText); this.$store.commit('cacheCollector/RESET_NEW_CACHE'); - this.$router.push({ path: '/overview' }); + this.$router.push({path: '/overview'}); }).catch((error) => { // Error let msg; @@ -179,16 +218,17 @@ console.log('Error', error.message); } console.log(error.config); - this.$store.commit('dialog/NEW_MESSAGE_DIALOG', { message: msg, title: title, }); + this.$store.commit('dialog/NEW_MESSAGE_DIALOG', {message: msg, title: title,}); }) - } else { + } else { // TODO update existing Cache } - }, + }, }, computed: { ...mapGetters({ - cache: 'cacheCollector/GET_CACHE' + cache: 'cacheCollector/GET_CACHE', + endStation: 'cacheCollector/GET_ENDSTATION' }), // computedCache: { // set(value) { diff --git a/frontend/src/pages/CacheEnd.vue b/frontend/src/pages/CacheEnd.vue index f046bfd..faf8813 100644 --- a/frontend/src/pages/CacheEnd.vue +++ b/frontend/src/pages/CacheEnd.vue @@ -1,18 +1,18 @@ diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js index 2d2b3fc..79fa81c 100644 --- a/frontend/src/router/routes.js +++ b/frontend/src/router/routes.js @@ -16,9 +16,9 @@ const routes = [ children: [{ path: "", component: () => import("pages/Cache.vue") }] }, { - path: "/qr-code-test/", + path: "/qr-scanner/", component: () => import("layouts/MyLayout.vue"), - children: [{ path: "", component: () => import("pages/qr-code-test.vue") }] + children: [{ path: "", component: () => import("pages/qr-scanner.vue") }] }, { path: "/cache/:id", @@ -31,10 +31,20 @@ const routes = [ children: [{ path: "", component: () => import("pages/StationEdit.vue") }] }, { - path: "/station-l/:pos", + path: "/endstation/", + component: () => import("layouts/MyLayout.vue"), + children: [{ path: "", component: () => import("pages/StationEndEdit.vue") }] + }, + { + path: "/tempstation/:pos", component: () => import("layouts/MyLayout.vue"), children: [{path: "", component: () => import("pages/StationEdit.vue")}] }, + { + path: "/tempendstation/", + component: () => import("layouts/MyLayout.vue"), + children: [{path: "", component: () => import("pages/StationEndEdit.vue")}] + }, { path: "/station/:cache/:id", component: () => import("layouts/MyLayout.vue"), @@ -55,6 +65,11 @@ const routes = [ component: () => import("layouts/MyLayout.vue"), children: [{ path: "", component: () => import("pages/CacheStart.vue") }] }, + { + path: "/CacheEnd/:cache/", + component: () => import("layouts/MyLayout.vue"), + children: [{ path: "", component: () => import("pages/CacheEnd.vue") }] + }, { path: "/profile/", component: () => import("layouts/MyLayout.vue"), diff --git a/frontend/src/store/cacheCollector/getters.js b/frontend/src/store/cacheCollector/getters.js index b2b2dbe..d2bea70 100644 --- a/frontend/src/store/cacheCollector/getters.js +++ b/frontend/src/store/cacheCollector/getters.js @@ -6,3 +6,7 @@ export const GET_TEMPSTATION = (state) => { console.log("GET_TEMPSTATION: retrieve cache from store. "); return state.tempStation; }; +export const GET_ENDSTATION = (state) => { + console.log("GET_ENDSTATION: retrieve cache from store. "); + return state.endStation; +}; diff --git a/frontend/src/store/cacheCollector/mutations.js b/frontend/src/store/cacheCollector/mutations.js index 383330d..72f58e1 100644 --- a/frontend/src/store/cacheCollector/mutations.js +++ b/frontend/src/store/cacheCollector/mutations.js @@ -6,6 +6,10 @@ export const SET_TEMPSTATION = (state, station) => { console.log("SET_TEMPSTATION: add new station to cache: "+station); state.tempStation = station; }; +export const SET_ENDSTATION = (state, station) => { + console.log("SET_ENDSTATION: "+station); + state.endStation = station; +}; export const ADD_STATION = (state, station) => { console.log("ADD_STATION: add new station to cache: "+station); state.newCache.stationen.push(station); @@ -29,6 +33,11 @@ export const RESET_NEW_CACHE = (state) => { rankingPoints: 0, stationen: [] }; + state.endStation = { + description: "Endstation", + longitude: 0.0001, + lattitude: 0.0001, + }; console.log("resetted new Cache"); }; export const LOAD_REMOTE_CACHE = (state, id) => { diff --git a/frontend/src/store/cacheCollector/state.js b/frontend/src/store/cacheCollector/state.js index 7087a3a..0f32de1 100644 --- a/frontend/src/store/cacheCollector/state.js +++ b/frontend/src/store/cacheCollector/state.js @@ -3,6 +3,7 @@ export default { name: "", description: "", rankingPoints: 0, + reward: "", stationen: [] }, // newCache: { @@ -41,4 +42,9 @@ export default { // ] // }, tempStation: {}, + endStation: { + description: "Endstation", + longitude: 9.206628, + lattitude: 49.147734, + }, } diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 6cbad26..ac8fd0e 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -61,87 +61,88 @@ public class Controller { return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll())); } - @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)); - } - } + // 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/checkStation") @@ -208,12 +209,39 @@ public class Controller { return ResponseEntity.status(400).body("The scanned station isn´t the correct following station"); } + if (!cache.getStationen().contains(station)) { + return ResponseEntity.status(400).body("The scanned station isnt a part of the cache"); + } + //---------------------- //Get Bearbeitet entry ResponseEntity getBearbeitet = FinderUtil.findBearbeitetByUserAndCache(user, cache); if (getBearbeitet.getStatusCodeValue() != 200) { - return getBearbeitet; + if (cache.getStationen().get(0).equals(station)) { + // start Cache + Bearbeitet bearbeitet = new Bearbeitet(); + bearbeitet.setUser(user); + bearbeitet.setCache(cache); + bearbeitet.setAktuelleStation(station); + + //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 { + return getBearbeitet; + } } Bearbeitet bearbeitet = (Bearbeitet) getBearbeitet.getBody(); @@ -225,10 +253,6 @@ public class Controller { return ResponseEntity.status(400).body("Database Error"); } - if (!cache.getStationen().contains(station)) { - return ResponseEntity.status(400).body("The scanned station isnt a part of the cache"); - } - int i = cache.getStationen().indexOf(station); if (i == 0) {