From 283f56e02d541163e4c86b59ce39b463dbbb9507 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Tue, 9 Apr 2019 16:49:17 +0200 Subject: [PATCH 1/7] There cant be two bearbeitet entities in the db featuring the same cache and user --- .../hhn/labsw/bugageocaching/controller/Controller.java | 7 ++++++- .../bugageocaching/repositories/BearbeitetRepository.java | 3 +++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index a97359a..3a6fe55 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -126,7 +126,6 @@ public class Controller { .setSigningKey(key) .parseClaimsJws(token).getBody(); - User user = userRepository.findByUsername(claims.getSubject()); if (user == null) { return ResponseEntity.status(404).body("User was not found"); @@ -136,6 +135,12 @@ public class Controller { Optional cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID)); if (cacheOptional.isPresent()) { Cache cache = cacheOptional.get(); + + if(bearbeitetRepository.findByUserAndCache(user, cache) != null){ + Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache); + return ResponseEntity.status(400).body(bearbeitet1.getAktuelleStation()); + } + bearbeitet.setCache(cache); Station startStation = cache.getStationen().get(0); diff --git a/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java b/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java index ac5484c..4b5c1a0 100644 --- a/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java +++ b/src/main/java/hhn/labsw/bugageocaching/repositories/BearbeitetRepository.java @@ -1,8 +1,11 @@ package hhn.labsw.bugageocaching.repositories; import hhn.labsw.bugageocaching.entities.Bearbeitet; +import hhn.labsw.bugageocaching.entities.Cache; +import hhn.labsw.bugageocaching.entities.User; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.repository.CrudRepository; public interface BearbeitetRepository extends JpaRepository { + Bearbeitet findByUserAndCache(User user, Cache cache); } From 59103da8ac22bd4781e5cf8fdef88a5da78e06f2 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Tue, 9 Apr 2019 16:51:01 +0200 Subject: [PATCH 2/7] Changed responeentity json param. --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 3a6fe55..fbe3e23 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -138,7 +138,7 @@ public class Controller { if(bearbeitetRepository.findByUserAndCache(user, cache) != null){ Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache); - return ResponseEntity.status(400).body(bearbeitet1.getAktuelleStation()); + return ResponseEntity.status(400).body(bearbeitet1); } bearbeitet.setCache(cache); From 1cd7e29fc1d585cb54a8efae85b2689af18b6351 Mon Sep 17 00:00:00 2001 From: Maximilian Leopold Date: Tue, 9 Apr 2019 16:54:19 +0200 Subject: [PATCH 3/7] Changed HTTP Respnse code --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index fbe3e23..cf052cc 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -138,7 +138,7 @@ public class Controller { if(bearbeitetRepository.findByUserAndCache(user, cache) != null){ Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache); - return ResponseEntity.status(400).body(bearbeitet1); + return ResponseEntity.status(200).body(bearbeitet1); } bearbeitet.setCache(cache); @@ -160,7 +160,7 @@ public class Controller { bearbeitetRepository.save(bearbeitet); - return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet)); + return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet)); } catch (ExpiredJwtException e) { return ResponseEntity.status(400).body("JWT Token expired"); } catch (Exception e){ From 1c7a34a7352d6c12cf325a3d5b745574797df208 Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Wed, 10 Apr 2019 00:16:28 +0200 Subject: [PATCH 4/7] =?UTF-8?q?Finished=20=E2=80=9Ecreate=20Cache/Station?= =?UTF-8?q?=E2=80=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixed Login and Frontend Usermanagement, implemented delete Cache, fixed some problems with store logic and router --- frontend/src/pages/Cache.vue | 15 ++- frontend/src/pages/Login.vue | 116 +++++++++-------- frontend/src/pages/Overview.vue | 117 +++++++++++------- frontend/src/pages/StationEdit.vue | 33 ++--- frontend/src/pages/StationView.vue | 44 ++++++- frontend/src/router/routes.js | 14 +-- frontend/src/store/auth/getters.js | 26 +++- frontend/src/store/auth/mutations.js | 38 +++++- frontend/src/store/auth/state.js | 27 ++-- .../src/store/cacheCollector/mutations.js | 11 +- frontend/src/store/cacheCollector/state.js | 72 ++++++----- frontend/src/store/index.js | 3 +- .../bugageocaching/controller/Controller.java | 8 +- 13 files changed, 330 insertions(+), 194 deletions(-) diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index 5d6b325..07b9355 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -19,6 +19,7 @@
- +
@@ -94,7 +95,7 @@ created: function () { console.log("isNewCache: " + this.isNewCache); console.log("fetch Caches from Store"); - this.tempCache = JSON.parse(JSON.stringify(this.cache)) + this.tempCache = JSON.parse(JSON.stringify(this.cache)); }, beforeMount: function () { }, @@ -137,15 +138,16 @@ const station = this.cache.stationen[index]; console.log(station) if (station.hasOwnProperty('id') ) { - this.$router.push({ path: '/station/'+station.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?local=${index}` }); // add parameter + this.$router.push({ path: `/station-l/${index}` }); // add parameter } }, - deleteStation() { - + deleteStation(index) { + // TODO wenn Station id hat, mit Backend abgleichen + this.$store.commit('cacheCollector/REMOVE_STATION', index); }, saveCache() { // commit to store, send to api, if success -> reset store @@ -155,6 +157,7 @@ this.$axios.post('http://localhost:8080/api/createCache', this.cache) .then((response) => { console.log("POST api/createCache: " + response.statusText); + this.$store.commit('cacheCollector/RESET_NEW_CACHE'); this.$router.push({ path: '/overview' }); }) .catch((error) => { diff --git a/frontend/src/pages/Login.vue b/frontend/src/pages/Login.vue index 320019d..e6fc7fd 100644 --- a/frontend/src/pages/Login.vue +++ b/frontend/src/pages/Login.vue @@ -1,48 +1,50 @@ diff --git a/frontend/src/router/routes.js b/frontend/src/router/routes.js index 2b285ca..bcecad6 100644 --- a/frontend/src/router/routes.js +++ b/frontend/src/router/routes.js @@ -20,25 +20,19 @@ const routes = [ children: [{ path: "", component: () => import("pages/Cache.vue") }] }, { - path: "/station?local=:pos", + path: "/station/", component: () => import("layouts/MyLayout.vue"), children: [{ path: "", component: () => import("pages/StationEdit.vue") }] }, { - path: "/station/:id", + path: "/station/:cache/:id", component: () => import("layouts/MyLayout.vue"), children: [{ path: "", component: () => import("pages/StationView.vue") }] }, { - path: "/station/", + path: "/station-l/:pos", component: () => import("layouts/MyLayout.vue"), - // props: true, - children: [{ - path: "", - component: () => import("pages/StationEdit.vue"), - // props: true - //props: ['stationObject'] - }] + children: [{ path: "", component: () => import("pages/StationEdit.vue") }] }, { path: "/login/", diff --git a/frontend/src/store/auth/getters.js b/frontend/src/store/auth/getters.js index cc054a3..da66d9b 100644 --- a/frontend/src/store/auth/getters.js +++ b/frontend/src/store/auth/getters.js @@ -1,4 +1,24 @@ -/* -export function someGetter (state) { +/** + * @return {boolean} + */ +export function GET_ADMINSTATE(state) { + console.log("GET_ADMINSTATE()"); + if (state.userAuthenticated !== null) { + console.log(state.userAuthenticated.roles.find(x => x.name === "admin") != null); + return state.userAuthenticated.roles.find(x => x.name === "admin") != null; + } else { + console.log(state.userAuthenticated); + return false; + } } -*/ + +// /** +// * @return {boolean} +// */ +// export function IS_AUTHENTICATED(state) { +// console.log("IS_AUTHENTICATED()"); +// console.log(JSON.parse(localStorage.getItem('userToken'))); +// console.log(!(JSON.parse(localStorage.getItem('userToken')) === null)); +// console.log(!(localStorage.getItem('userToken') === null)); +// return !(localStorage.getItem('userToken') === null); +// } diff --git a/frontend/src/store/auth/mutations.js b/frontend/src/store/auth/mutations.js index 3a5c061..fed76c1 100644 --- a/frontend/src/store/auth/mutations.js +++ b/frontend/src/store/auth/mutations.js @@ -1,17 +1,43 @@ +import axios from 'axios' export const SET_AUTHENTICATED = (state) => { console.log("SET_AUTHENTICATED()"); console.log(JSON.parse(localStorage.getItem('userToken'))); if (localStorage.getItem('userToken')) { - state.userAuthenticated.isAuthenticated = true; + state.isAuthenticated = true; } else { - state.userAuthenticated.isAuthenticated = false; + state.isAuthenticated = false; } }; -export const SET_USER_PROPERTIES = (state, user) => { - console.log("SET_USER_PROPERTIES()"); - console.log("still todo!"); -}; export const SET_LOGOUT = (state) => { console.log("SET_LOGOUT()"); + localStorage.removeItem('userToken'); state.userAuthenticated = null; + state.isAuthenticated = false; + console.log(localStorage.getItem('userToken')); }; +export const SET_USER = (state) => { + console.log("SET_USER()"); + if (localStorage.getItem('userToken')) { + axios.get('http://localhost:8080/api/getUser', { + params: { + token: JSON.parse(localStorage.getItem('userToken')) + } + }) + .then((response) => { + console.log("GET/POST http://localhost:8080/api/getUser - response: "); + console.log(response.data); + state.userAuthenticated = response.data; + state.isAuthenticated = true; + if (state.userAuthenticated.hasOwnProperty('password')) delete state.userAuthenticated.password; + console.log(state.userAuthenticated); + }) + .catch((error) => { + console.log("Catch Block: ") + console.log(error) + }); + } else { + state.isAuthenticated = false; + state.userAuthenticated = null; + } +}; + diff --git a/frontend/src/store/auth/state.js b/frontend/src/store/auth/state.js index 1fee418..902a77e 100644 --- a/frontend/src/store/auth/state.js +++ b/frontend/src/store/auth/state.js @@ -1,12 +1,19 @@ export default { - userAuthenticated: { - id: 1, - firstname: "t", - lastname: "v", - username: "mo", - email: "test@user.com", - rankingPointsSum: 345, - isAuthenticated: false, - isAdmin: true, - }, + isAuthenticated: false, + userAuthenticated: null, + // userAuthenticated: { + // id: 1, + // firstname: "Timo", + // lastname: "Volkmann", + // username: "moximoti", + // rankingPointsSum: 0, + // email: "test@user.com", + // password: "$2a$10$c3Fo5nuUG.nlwXP94qc7qO01/UC1OL2DebEm.5zYlisKJGRhXMnqq", + // roles: [ + // { + // id: 0, + // name: "admin" + // } + // ] + // }, } diff --git a/frontend/src/store/cacheCollector/mutations.js b/frontend/src/store/cacheCollector/mutations.js index ee2cab7..646ab0f 100644 --- a/frontend/src/store/cacheCollector/mutations.js +++ b/frontend/src/store/cacheCollector/mutations.js @@ -10,17 +10,20 @@ export const ADD_STATION = (state, station) => { console.log("ADD_STATION: add new station to cache: "+station); state.newCache.stationen.push(station); }; -export const EDIT_STATION = (state, index, station) => { - console.log("ADD_STATION: add new station to cache: "+station); +export const EDIT_STATION = (state, indexStation) => { + let index, station; + index = indexStation.index; + station = indexStation.station; + console.log("EDIT_STATION: "+index+" "+station); + state.newCache.stationen[index] = station; }; export const REMOVE_STATION = (state, index) => { - console.log("ADD_STATION: add new station to cache: "+station); + console.log("REMOVE_STATION: "+index); state.newCache.stationen.splice(index,1); }; export const RESET_NEW_CACHE = (state) => { state.newCache = { - id: null, name: "", description: "", rankingPoints: 0, diff --git a/frontend/src/store/cacheCollector/state.js b/frontend/src/store/cacheCollector/state.js index 3836b13..7087a3a 100644 --- a/frontend/src/store/cacheCollector/state.js +++ b/frontend/src/store/cacheCollector/state.js @@ -1,38 +1,44 @@ export default { newCache: { - name: "Blumencache", - description: "Dieser Cache umfasst 4 Stationen mit Rätseln rund um das Thema Blumen", - rankingPoints: 100, - stationen: [ - { - description: "Ein kleines winterliches Schlaginstrument. Welche Blume ist damit gemeint?", - longitude: 9.206628, - lattitude: 49.147734, - code: 213812, - solution: "Schneeglöckchen" - }, - { - description: "Ein blühendes Federvieh. Welche Blume ist damit gemeint?", - longitude: 9.206806, - lattitude: 49.147318, - code: 237823, - solution: "Gänseblümchen" - }, - { - description: "Eine wertvolle Farbe. Welche Blume ist damit gemeint?", - longitude: 9.207844, - lattitude: 49.148032, - code: 899423, - solution: "Edelweiß" - }, - { - description: "Ein Zerkleinerungsgerät in der Brüllöffnung eines Raubtieres. Welche Blume ist damit gemeint?", - longitude: 9.207649, - lattitude: 49.150142, - code: 347923, - solution: "Löwenzahn" - } - ] + name: "", + description: "", + rankingPoints: 0, + stationen: [] }, + // newCache: { + // name: "Blumencache", + // description: "Dieser Cache umfasst 4 Stationen mit Rätseln rund um das Thema Blumen", + // rankingPoints: 100, + // stationen: [ + // { + // description: "Ein kleines winterliches Schlaginstrument. Welche Blume ist damit gemeint?", + // longitude: 9.206628, + // lattitude: 49.147734, + // code: 213812, + // solution: "Schneeglöckchen" + // }, + // { + // description: "Ein blühendes Federvieh. Welche Blume ist damit gemeint?", + // longitude: 9.206806, + // lattitude: 49.147318, + // code: 237823, + // solution: "Gänseblümchen" + // }, + // { + // description: "Eine wertvolle Farbe. Welche Blume ist damit gemeint?", + // longitude: 9.207844, + // lattitude: 49.148032, + // code: 899423, + // solution: "Edelweiß" + // }, + // { + // description: "Ein Zerkleinerungsgerät in der Brüllöffnung eines Raubtieres. Welche Blume ist damit gemeint?", + // longitude: 9.207649, + // lattitude: 49.150142, + // code: 347923, + // solution: "Löwenzahn" + // } + // ] + // }, tempStation: {}, } diff --git a/frontend/src/store/index.js b/frontend/src/store/index.js index 8eb6c71..0ce2a96 100644 --- a/frontend/src/store/index.js +++ b/frontend/src/store/index.js @@ -22,7 +22,8 @@ export default function (/* { ssrContext } */) { // enable strict mode (adds overhead!) // for dev mode only - strict: process.env.DEV + //strict: process.env.DEV + strict: false }) /* diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index cf052cc..477d1f1 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -199,7 +199,9 @@ public class Controller { @RequestMapping("/api/createCache") @ResponseBody public ResponseEntity createCache(@RequestBody Cache cache) { - + System.out.println(cache.getName()); + System.out.println(cache.getStationen().size()); + System.out.println(cache.getStationen().get(0).getId()); // Stationen werden in die Datenbank eingetragen for (Station station : cache.getStationen()) { ResponseEntity response = createStation(station); @@ -208,7 +210,7 @@ public class Controller { return response; } } - + System.out.println("Stationen eingetragen!"); // Caches werden in die Datenbank eingetragen if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0 || cache.getStationen().size() == 0) { deleteStationen(cache); @@ -234,7 +236,7 @@ public class Controller { public ResponseEntity createStation(Station station) { - if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 || station.getSolution().length() == 0) { + if (station.getDescription().length() == 0 || station.getLattitude() == 0.0 || station.getLongitude() == 0.0 /*|| station.getSolution().length() == 0*/) { return ResponseEntity.status(400).body("station fields can´t be empty"); } From 1c602c1dabc2284d8f0a3ffb8ead633340b9aed2 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 11 Apr 2019 02:54:53 +0200 Subject: [PATCH 5/7] deleteCache deletes all stations related to taht cache now --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 477d1f1..c698928 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -335,6 +335,10 @@ public class Controller { } } + for(Station station : cache.getStationen()) { + stationRepository.delete(station); + } + cacheRepository.delete(cache); return ResponseEntity.status(200).body(new Gson().toJson(true)); From 9828f88f7b3fee9f9a87f8b7994d34fa9c6162fb Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 11 Apr 2019 02:56:01 +0200 Subject: [PATCH 6/7] a cache needs atleast 2 stations now(start and endstation) --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index c698928..c0b73b3 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -212,7 +212,7 @@ public class Controller { } System.out.println("Stationen eingetragen!"); // Caches werden in die Datenbank eingetragen - if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0 || cache.getStationen().size() == 0) { + if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0 || cache.getStationen().size() < 2) { deleteStationen(cache); return ResponseEntity.status(400).body("cache fields can´t be empty"); } From 16cae0ba903a48624dc00f91a411ad5261228dcb Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 11 Apr 2019 03:20:17 +0200 Subject: [PATCH 7/7] fixed a bug with deleteCache --- .../bugageocaching/controller/Controller.java | 51 +++++++++++-------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index c0b73b3..397ef33 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*; import javax.annotation.PostConstruct; import javax.xml.bind.DatatypeConverter; +import java.lang.reflect.Array; import java.security.Key; import java.security.SecureRandom; import java.util.*; @@ -136,34 +137,34 @@ public class Controller { if (cacheOptional.isPresent()) { Cache cache = cacheOptional.get(); - if(bearbeitetRepository.findByUserAndCache(user, cache) != null){ + 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); - } else { - return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID); - } + Station startStation = cache.getStationen().get(0); + bearbeitet.setAktuelleStation(startStation); + } else { + return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID); + } - Optional cacheAccesDefinitionOptional = - cacheAccesDefinitionRepository.findById(0); // angefangen - if (cacheAccesDefinitionOptional.isPresent()) { - CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get(); - bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); - } else { - return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0); - } + Optional cacheAccesDefinitionOptional = + cacheAccesDefinitionRepository.findById(0); // angefangen + if (cacheAccesDefinitionOptional.isPresent()) { + CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get(); + bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); + } else { + return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0); + } bearbeitetRepository.save(bearbeitet); return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet)); } catch (ExpiredJwtException e) { return ResponseEntity.status(400).body("JWT Token expired"); - } catch (Exception e){ + } catch (Exception e) { return ResponseEntity.status(400).body("JWT Token invalid"); } @@ -201,7 +202,7 @@ public class Controller { public ResponseEntity createCache(@RequestBody Cache cache) { System.out.println(cache.getName()); System.out.println(cache.getStationen().size()); - System.out.println(cache.getStationen().get(0).getId()); +// System.out.println(cache.getStationen().get(0).getId()); // Stationen werden in die Datenbank eingetragen for (Station station : cache.getStationen()) { ResponseEntity response = createStation(station); @@ -292,9 +293,9 @@ public class Controller { .parseClaimsJws(token).getBody(); return ResponseEntity.status(200).body(claims.get("admin")); - }catch (ExpiredJwtException e) { + } catch (ExpiredJwtException e) { return ResponseEntity.status(400).body("JWT Token expired"); - } catch (Exception e){ + } catch (Exception e) { return ResponseEntity.status(400).body("JWT Token invalid"); } @@ -335,12 +336,18 @@ public class Controller { } } - for(Station station : cache.getStationen()) { - stationRepository.delete(station); + ArrayList stationen = new ArrayList<>(); + for (Station station : cache.getStationen()) { + stationen.add(stationRepository.findById(station.getId()).get()); } cacheRepository.delete(cache); + for (Station station : stationen) { + stationRepository.delete(station); + } + + return ResponseEntity.status(200).body(new Gson().toJson(true)); } @@ -371,7 +378,7 @@ public class Controller { } } catch (ExpiredJwtException e) { return ResponseEntity.status(400).body("JWT Token expired"); - } catch (Exception e){ + } catch (Exception e) { return ResponseEntity.status(400).body("JWT Token invalid"); } } @@ -412,7 +419,7 @@ public class Controller { } } catch (ExpiredJwtException e) { return ResponseEntity.status(400).body("JWT Token expired"); - } catch (Exception e){ + } catch (Exception e) { return ResponseEntity.status(400).body("JWT Token invalid"); } }