From fd0328557322ce9cede00fd5a6c0a51981ca608e Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Mon, 13 May 2019 12:30:42 +0200 Subject: [PATCH 1/9] typo in warning --- frontend/quasar.conf.js | 3 ++- frontend/src/router/index.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/frontend/quasar.conf.js b/frontend/quasar.conf.js index 3765fb7..d4ff378 100644 --- a/frontend/quasar.conf.js +++ b/frontend/quasar.conf.js @@ -72,7 +72,8 @@ module.exports = function (ctx) { 'QPopupEdit', 'QSlideTransition', 'QToggle', - 'QLinearProgress' + 'QLinearProgress', + 'QBtnGroup' ], directives: [ diff --git a/frontend/src/router/index.js b/frontend/src/router/index.js index c9ba718..98ea71b 100644 --- a/frontend/src/router/index.js +++ b/frontend/src/router/index.js @@ -70,7 +70,7 @@ export default function ({store}/* { store, ssrContext } */) { console.log(error.response.headers); //store.commit('auth/SET_LOGOUT'); store.commit('dialog/NEW_MESSAGE_DIALOG', { - message: "Ihr Token ist nicht mehr gültig. Bitte loggen Sie sich erneut ein.", + message: "Ihre Session ist abgelaufen. Bitte loggen Sie sich erneut ein.", title: "Bitte erneut anmelden.", color: "blue", }); From c1dcba7c0499c0d08a1784ac2a0d18c0f072a989 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 May 2019 15:34:34 +0200 Subject: [PATCH 2/9] first implementation of editCache --- .../bugageocaching/controller/Controller.java | 48 +++++----- .../util/CacheConstructionUtil.java | 92 +++++++++++++++++++ 2 files changed, 118 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 2385965..72027ea 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -6,6 +6,7 @@ import hhn.labsw.bugageocaching.helper.POI; import hhn.labsw.bugageocaching.helper.RankingListHelper; import hhn.labsw.bugageocaching.helper.TeamRankingListHelper; import hhn.labsw.bugageocaching.repositories.*; +import hhn.labsw.bugageocaching.util.CacheConstructionUtil; import hhn.labsw.bugageocaching.util.FinderUtil; import hhn.labsw.bugageocaching.util.VerificationUtil; import io.jsonwebtoken.Claims; @@ -24,6 +25,7 @@ import java.util.List; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.createCacheUtil; import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.deleteCacheUtil; +import static hhn.labsw.bugageocaching.util.CacheConstructionUtil.editCacheUtil; import static hhn.labsw.bugageocaching.util.VerificationUtil.fetchPublicKey; @RestController @@ -57,7 +59,7 @@ public class Controller { TeamInviteRepository teamInviteRepository; @PostConstruct - public void init(){ + public void init() { fetchPublicKey(); } @@ -333,28 +335,30 @@ public class Controller { @CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose @RequestMapping(value = "/api/editCache", method = RequestMethod.PUT, produces = "application/json") @ResponseBody - public ResponseEntity editCache(@RequestBody Cache newCache){ + public ResponseEntity editCache(@RequestBody Cache newCache) { - //---------------------- - //Get Cache - ResponseEntity getCache = FinderUtil.findCacheById(newCache.getId() + ""); +// //---------------------- +// //Get Cache +// ResponseEntity getCache = FinderUtil.findCacheById(newCache.getId() + ""); +// +// if (getCache.getStatusCodeValue() != 200) { +// return getCache; +// } +// +// Cache oldCache = (Cache) getCache.getBody(); +// //---------------------- +// +// oldCache.setDescription(newCache.getDescription()); +// oldCache.setName(newCache.getName()); +// oldCache.setRankingPoints(newCache.getRankingPoints()); +// oldCache.setReward(newCache.getReward()); +// oldCache.setStationen(newCache.getStationen()); +// +// cacheRepository.save(oldCache); +// +// return ResponseEntity.status(200).body("Cache edited"); - if (getCache.getStatusCodeValue() != 200) { - return getCache; - } - - Cache oldCache = (Cache) getCache.getBody(); - //---------------------- - - oldCache.setDescription(newCache.getDescription()); - oldCache.setName(newCache.getName()); - oldCache.setRankingPoints(newCache.getRankingPoints()); - oldCache.setReward(newCache.getReward()); - oldCache.setStationen(newCache.getStationen()); - - cacheRepository.save(oldCache); - - return ResponseEntity.status(200).body("Cache edited"); + return editCacheUtil(newCache); } @ApiOperation(value = "Checks if the given User has an admin role") @@ -823,7 +827,7 @@ public class Controller { List teamInvitesList = teamInviteRepository.findByUser(user); - for (TeamInvite tmp : teamInvitesList){ + for (TeamInvite tmp : teamInvitesList) { tmp.setUser(null); } diff --git a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java index 5deb9c5..959c2f5 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java @@ -13,6 +13,7 @@ import org.springframework.stereotype.Component; import javax.persistence.RollbackException; import java.util.ArrayList; +import java.util.List; import java.util.Optional; import java.util.Random; @@ -120,6 +121,87 @@ public class CacheConstructionUtil { return ResponseEntity.status(200).body(new Gson().toJson(station)); } + public static ResponseEntity editCacheUtil(Cache cache) { + Optional oldCacheOptional = cacheRepository.findById(cache.getId()); + Cache oldCache; + if (oldCacheOptional.isPresent()) { + oldCache = oldCacheOptional.get(); + } else { + return ResponseEntity.status(404).body("There isnt a cache with the id " + cache.getId()); + } + + ResponseEntity response; + List newCreatedStationList = new ArrayList(); + for (Station station : cache.getStationen()) { + // wenn Station schon vorher vorhanden war, wird nur nach validen Daten geprüft + if (oldCache.getStationen().contains(station)) { + response = checkStationUtil(station); + } + // wenn Station neu hinzugefügt wurde, wird die Station zusätzlich in die Datenbank gespeichert + else { + response = createStationUtil(station); + if (response.getStatusCodeValue() == 200) { + newCreatedStationList.add(station); + } + } + if (response.getStatusCodeValue() == 400) { + // neu erzeugte Stationen werden gelöscht, falls es einen Fehler gibt + deleteNewCreatedStationsUtil(newCreatedStationList); + return response; + } + } + + for (Station station : oldCache.getStationen()) { + // wenn Station entfernt wurde, wird diese auch aus der Datenbank gelöscht + if (!cache.getStationen().contains(station)) { + stationRepository.delete(station); + } + } + + // überprüft den Cache nach validen Daten + if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("cache fields can´t be empty"); + } + + if (cache.getStationen().size() < 2) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("a cache needs atleast 2 stations"); + } + + for (Cache cache1 : cacheRepository.findAll()) { + if (cache1.getName().equals(cache.getName())) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("name is already taken"); + } + } + + if (cache.getRankingPoints() < 0) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("Ranking points has to be a positive number"); + } + + cacheRepository.save(cache); + + return ResponseEntity.status(200).body(new Gson().toJson(cache)); + } + + public static ResponseEntity checkStationUtil(Station station) { + 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"); + } + + if (station.getLattitude() < 9 || station.getLattitude() > 10) { + return ResponseEntity.status(400).body("Lattitude has to be between 9 and 10 degrees"); + } + + if (station.getLongitude() < 49 || station.getLongitude() > 50) { + return ResponseEntity.status(400).body("Longitude has to be in the range of 49 to 50 degrees"); + } + + return ResponseEntity.status(200).body(new Gson().toJson(station)); + } + public static void deleteStationenUtil(Cache cache) { for (Station station : cache.getStationen()) { try { @@ -130,6 +212,16 @@ public class CacheConstructionUtil { } } + public static void deleteNewCreatedStationsUtil(List newCreatedStationList) { + for (Station station : newCreatedStationList) { + try { + stationRepository.delete(station); + } catch (IllegalArgumentException e) { // station is null + // do nothing + } + } + } + public static ResponseEntity deleteCacheUtil(String cacheID) { Optional optionalCache = cacheRepository.findById(Integer.valueOf(cacheID)); if (!optionalCache.isPresent()) { From 30cb1d15796d57964b801e9e160c1bd97dad8352 Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 May 2019 15:41:13 +0200 Subject: [PATCH 3/9] a fix in editCache --- .../labsw/bugageocaching/util/CacheConstructionUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java index 959c2f5..7dc78ac 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java @@ -171,8 +171,10 @@ public class CacheConstructionUtil { for (Cache cache1 : cacheRepository.findAll()) { if (cache1.getName().equals(cache.getName())) { - deleteNewCreatedStationsUtil(newCreatedStationList); - return ResponseEntity.status(400).body("name is already taken"); + if (cache1 != oldCache) { + deleteNewCreatedStationsUtil(newCreatedStationList); + return ResponseEntity.status(400).body("name is already taken"); + } } } From 0d2ac9af37fc4ec611a6dc3c9c4162a0aa7af09a Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 14 May 2019 09:53:48 +0200 Subject: [PATCH 4/9] refactored code --- .../util/CacheConstructionUtil.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java index 7dc78ac..0f618b6 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/CacheConstructionUtil.java @@ -86,12 +86,12 @@ public class CacheConstructionUtil { return ResponseEntity.status(400).body("station fields can´t be empty"); } - if (station.getLattitude() < 9 || station.getLattitude() > 10) { + if (station.getLongitude() < 9 || station.getLongitude() > 10) { return ResponseEntity.status(400).body("Lattitude has to be between 9 and 10 degrees"); } - if (station.getLongitude() < 49 || station.getLongitude() > 50) { - return ResponseEntity.status(400).body("Longitude has to be in the range of 49 to 50 degrees"); + if (station.getLattitude() < 49 || station.getLattitude() > 50) { + return ResponseEntity.status(400).body("Lattitude has to be in the range of 49 to 50 degrees"); } Random r = new Random(); @@ -151,13 +151,6 @@ public class CacheConstructionUtil { } } - for (Station station : oldCache.getStationen()) { - // wenn Station entfernt wurde, wird diese auch aus der Datenbank gelöscht - if (!cache.getStationen().contains(station)) { - stationRepository.delete(station); - } - } - // überprüft den Cache nach validen Daten if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) { deleteNewCreatedStationsUtil(newCreatedStationList); @@ -185,6 +178,13 @@ public class CacheConstructionUtil { cacheRepository.save(cache); + for (Station station : oldCache.getStationen()) { + // wenn Station entfernt wurde, wird diese auch aus der Datenbank gelöscht + if (!cache.getStationen().contains(station)) { + stationRepository.delete(station); + } + } + return ResponseEntity.status(200).body(new Gson().toJson(cache)); } From 16381ac8c2eaff04875a1c4fa0e28115d25cb86b Mon Sep 17 00:00:00 2001 From: Timo Volkmann Date: Tue, 14 May 2019 10:17:06 +0200 Subject: [PATCH 5/9] implemented edit Cache, bugfixes --- frontend/src/pages/Cache.vue | 97 ++++++++----------- frontend/src/pages/Overview.vue | 13 ++- .../src/store/cacheCollector/mutations.js | 4 +- frontend/src/store/cacheCollector/state.js | 4 +- 4 files changed, 51 insertions(+), 67 deletions(-) diff --git a/frontend/src/pages/Cache.vue b/frontend/src/pages/Cache.vue index 42c9e40..d61d98d 100644 --- a/frontend/src/pages/Cache.vue +++ b/frontend/src/pages/Cache.vue @@ -1,7 +1,5 @@