From 4b16b6a2b1a4ba66998aee11918e0bacb8417633 Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 16 Apr 2019 10:17:36 +0200 Subject: [PATCH 1/2] returns bearbeitet instead of the station now so the frontend is able to see whether the cache is finished or not added a FinderUtil method for cacheAccesDefinition --- .../bugageocaching/controller/Controller.java | 18 ++++++++------- .../labsw/bugageocaching/util/FinderUtil.java | 23 +++++++++++-------- 2 files changed, 24 insertions(+), 17 deletions(-) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 66e1f5f..16ed376 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -279,16 +279,18 @@ public class Controller { if (cache.getStationen().get(i - 1).equals(aktuelleStation)) { bearbeitet.setAktuelleStation(station); if (i == cache.getStationen().size() - 1) { // letze Station erreicht - Optional cacheAccesDefinitionOptional = - cacheAccesDefinitionRepository.findById(1); // abgeschlossen - if (cacheAccesDefinitionOptional.isPresent()) { - CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get(); - bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); - } else { - return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 1); + //---------------------- + //Get CacheAccesDefinition + ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("1"); + + if (getCacheAccesDefinition.getStatusCodeValue() != 200) { + return getCacheAccesDefinition; } + + CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody(); + //---------------------- } - return ResponseEntity.status(200).body(new Gson().toJson(station)); + return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet)); } else { return ResponseEntity.status(400).body("The scanned station isn“t the correct following station"); } diff --git a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java index e128a12..21f4770 100644 --- a/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java +++ b/src/main/java/hhn/labsw/bugageocaching/util/FinderUtil.java @@ -1,9 +1,6 @@ package hhn.labsw.bugageocaching.util; -import hhn.labsw.bugageocaching.entities.Bearbeitet; -import hhn.labsw.bugageocaching.entities.Cache; -import hhn.labsw.bugageocaching.entities.Station; -import hhn.labsw.bugageocaching.entities.User; +import hhn.labsw.bugageocaching.entities.*; import hhn.labsw.bugageocaching.repositories.*; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.ResponseEntity; @@ -43,7 +40,7 @@ public class FinderUtil { } } - public static ResponseEntity findStationById(String stationID){ + public static ResponseEntity findStationById(String stationID) { Optional stationOptional = stationRepository.findById(Integer.valueOf(stationID)); if (stationOptional.isPresent()) { @@ -53,25 +50,33 @@ public class FinderUtil { } } - public static ResponseEntity findBearbeitetByUserAndCache(User user, Cache cache){ + public static ResponseEntity findBearbeitetByUserAndCache(User user, Cache cache) { Bearbeitet bearbeitet = bearbeitetRepository.findByUserAndCache(user, cache); - if(bearbeitet != null){ + if (bearbeitet != null) { return ResponseEntity.status(200).body(bearbeitet); } return ResponseEntity.status(404).body("The user has not started this cache yet"); } - public static ResponseEntity findUserByUsername(String username){ + public static ResponseEntity findUserByUsername(String username) { User user = userRepository.findByUsername(username); - if(user != null){ + if (user != null) { return ResponseEntity.status(200).body(user); } return ResponseEntity.status(404).body("Couldnt find user with username " + username); } + public static ResponseEntity findCacheAccesDefinitionById(String cacheAccesDefinitionID) { + Optional cacheAccesDefinitionOptional = cacheAccesDefinitionRepository.findById(Integer.valueOf(cacheAccesDefinitionID)); + if (cacheAccesDefinitionOptional.isPresent()) { + return ResponseEntity.status(200).body(cacheAccesDefinitionOptional.get()); + } else { + return ResponseEntity.status(404).body("Couldnt find CacheAccesDefinition " + cacheAccesDefinitionID); + } + } } From de852f08f412a0990cf1d673103560debfb3672e Mon Sep 17 00:00:00 2001 From: Michael Date: Tue, 16 Apr 2019 10:21:15 +0200 Subject: [PATCH 2/2] fixed a bug --- .../java/hhn/labsw/bugageocaching/controller/Controller.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java index 16ed376..685d553 100644 --- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java +++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java @@ -288,6 +288,7 @@ public class Controller { } CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody(); + bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); //---------------------- } return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet));