diff --git a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
index 6098d36..071dd3f 100644
--- a/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
+++ b/src/main/java/hhn/labsw/bugageocaching/controller/Controller.java
@@ -1,11 +1,13 @@
package hhn.labsw.bugageocaching.controller;
import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
import hhn.labsw.bugageocaching.entities.*;
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 +26,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
@@ -68,6 +71,7 @@ public class Controller {
@RequestMapping(value = "/api/allCaches", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getAllCaches() {
+ logger.warn("API CALL: /api/allCaches");
return ResponseEntity.status(200).body(new Gson().toJson(cacheRepository.findAll()));
}
@@ -232,11 +236,11 @@ public class Controller {
System.out.println(durchgefuehrterCache.getName());
if (!cacheID.equals(durchgefuehrterCacheID)) {
- return ResponseEntity.status(400).body("The scanned station isn´t the correct following station (Name)");
+ return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station");
}
if (!cache.getStationen().contains(station)) {
- return ResponseEntity.status(400).body("The scanned station isnt a part of the cache");
+ return ResponseEntity.status(400).body("Die gescannte Station gehört nicht zu dem gerade bearbeiteten Cache");
}
//----------------------
@@ -277,13 +281,13 @@ public class Controller {
Station aktuelleStation = bearbeitet.getAktuelleStation();
if (aktuelleStation == null) {
- return ResponseEntity.status(400).body("Database Error");
+ return ResponseEntity.status(400).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin");
}
int i = cache.getStationen().indexOf(station);
if (i == 0) {
- return ResponseEntity.status(400).body("The scanned station isn´t the correct following station (i==0)");
+ return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station");
}
if (cache.getStationen().get(i - 1).equals(aktuelleStation)) {
@@ -310,7 +314,7 @@ public class Controller {
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(nicht letzte)");
+ return ResponseEntity.status(400).body("Die gescannte Station ist nicht die korrekte nachfolge Station");
}
}
@@ -337,26 +341,7 @@ public class Controller {
@ResponseBody
public ResponseEntity editCache(@RequestBody Cache newCache) {
- //----------------------
- //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");
+ return editCacheUtil(newCache);
}
@ApiOperation(value = "Checks if the given User has an admin role")
@@ -405,6 +390,7 @@ public class Controller {
@RequestMapping(value = "/api/getAllStations", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public ResponseEntity getAllStations() {
+ logger.warn("API CALL: /api/getAllStations");
return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll()));
}
@@ -416,6 +402,7 @@ public class Controller {
@RequestMapping(value = "/api/deleteCache", method = {RequestMethod.DELETE, RequestMethod.GET}, produces = "application/json")
@ResponseBody
public ResponseEntity deleteCache(@RequestParam String cacheID) {
+ logger.warn("API CALL: /api/deleteCache");
return deleteCacheUtil(cacheID);
}
@@ -430,6 +417,7 @@ public class Controller {
@ResponseBody
public ResponseEntity getMyCaches(@RequestParam String token) {
+ logger.warn("API CALL: /api/getMyCaches");
ResponseEntity verifyToken = VerificationUtil.verifyToken(token);
@@ -439,6 +427,8 @@ public class Controller {
Claims claims = (Claims) verifyToken.getBody();
+ logger.debug("/api/getMyCaches Token verified");
+
ResponseEntity getUser = FinderUtil.findUserFromClaim(claims);
if (getUser.getStatusCodeValue() != 200) {
@@ -447,17 +437,21 @@ public class Controller {
User user = (User) getUser.getBody();
- if (user != null) {
- ArrayList
bearbeitetList = new ArrayList<>();
+ logger.debug("/api/getMyCaches Got User: " + user.getEmail());
- for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) {
+ if (user != null) {
+ //ArrayList bearbeitetList = new ArrayList<>();
+
+ /*for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) {
if (bearbeitet.getUser().getId() == user.getId()) {
bearbeitetList.add(bearbeitet);
}
- }
+ }*/
+ List bearbeitetList = bearbeitetRepository.findByUser(user);
+ logger.debug("/api/getMyCaches Got all bearbeitet entreis of user: " +user.getEmail());
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList));
} else {
- return ResponseEntity.status(404).body("User was not found in the database");
+ return ResponseEntity.status(404).body("Es gab einen Fehler. Bitte versuche es erneut oder kontaktiere einen Admin!");
}
}
@@ -470,13 +464,19 @@ public class Controller {
@ResponseBody
public ResponseEntity getRankingList() {
+ logger.warn("API CALL: /api/getRankingList");
+
List sendBackUsers = new LinkedList<>();
+
+ logger.debug("/api/getRankingList create sendBackUsers");
List