Fehlermeldungen CacheConstruction

This commit is contained in:
Maximilian Leopold 2019-05-14 12:05:19 +02:00
parent 074a18a831
commit 9d56f2720a
2 changed files with 11 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package hhn.labsw.bugageocaching.controller; package hhn.labsw.bugageocaching.controller;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import hhn.labsw.bugageocaching.entities.*; import hhn.labsw.bugageocaching.entities.*;
import hhn.labsw.bugageocaching.helper.POI; import hhn.labsw.bugageocaching.helper.POI;
import hhn.labsw.bugageocaching.helper.RankingListHelper; import hhn.labsw.bugageocaching.helper.RankingListHelper;
@ -492,6 +493,7 @@ public class Controller {
sendBackUsers.add(tmp); sendBackUsers.add(tmp);
} }
logger.debug("/api/getRankingList Converted Objects to RankingListHelper"); logger.debug("/api/getRankingList Converted Objects to RankingListHelper");
logger.debug("/api/getRankingList RankingList: " + new GsonBuilder().setPrettyPrinting().create().toJson(sendBackUsers));
return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers)); return ResponseEntity.status(200).body(new Gson().toJson(sendBackUsers));
} }

View File

@ -54,24 +54,24 @@ public class CacheConstructionUtil {
// Caches werden in die Datenbank eingetragen // Caches werden in die Datenbank eingetragen
if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) { if (cache.getDescription().length() == 0 || cache.getName().length() == 0 || cache.getRankingPoints() == 0.0) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("cache fields can´t be empty"); return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
} }
if (cache.getStationen().size() < 2) { if (cache.getStationen().size() < 2) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("a cache needs atleast 2 stations"); return ResponseEntity.status(400).body("Ein Cache muss mindestens zwei Stationen besitzen.\nBitte füge noch eine Station hinzu!");
} }
for (Cache cache1 : cacheRepository.findAll()) { for (Cache cache1 : cacheRepository.findAll()) {
if (cache1.getName().equals(cache.getName())) { if (cache1.getName().equals(cache.getName())) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("name is already taken"); return ResponseEntity.status(400).body("Der Cachename ist bereits vergeben. Bitte wähle einen anderen Name!");
} }
} }
if (cache.getRankingPoints() < 0) { if (cache.getRankingPoints() < 0) {
deleteStationenUtil(cache); deleteStationenUtil(cache);
return ResponseEntity.status(400).body("Ranking points has to be a positive number"); return ResponseEntity.status(400).body("Die Punkte für den Cache dürfen nicht negativ sein!");
} }
cacheRepository.save(cache); cacheRepository.save(cache);
@ -82,15 +82,15 @@ public class CacheConstructionUtil {
public static ResponseEntity createStationUtil(Station station) { public static ResponseEntity createStationUtil(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"); return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
} }
if (station.getLattitude() < 9 || station.getLattitude() > 10) { if (station.getLattitude() < 9 || station.getLattitude() > 10) {
return ResponseEntity.status(400).body("Lattitude has to be between 9 and 10 degrees"); return ResponseEntity.status(400).body("Die Lattitude ist außerhalb der Bundesgartenschau");
} }
if (station.getLongitude() < 49 || station.getLongitude() > 50) { 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(400).body("Die Longitude ist außerhalb der Bundesgartenschau");
} }
Random r = new Random(); Random r = new Random();
@ -112,7 +112,7 @@ public class CacheConstructionUtil {
try { try {
station.setCode(code); station.setCode(code);
} catch (RollbackException e) { } catch (RollbackException e) {
return ResponseEntity.status(400).body("There was an error generating the unique code"); return ResponseEntity.status(400).body("Es gab einen Fehler beim Konsturieren der QR Codes");
} }
stationRepository.save(station); stationRepository.save(station);
@ -133,7 +133,7 @@ public class CacheConstructionUtil {
public static ResponseEntity deleteCacheUtil(String cacheID) { public static ResponseEntity deleteCacheUtil(String cacheID) {
Optional<Cache> optionalCache = cacheRepository.findById(Integer.valueOf(cacheID)); Optional<Cache> optionalCache = cacheRepository.findById(Integer.valueOf(cacheID));
if (!optionalCache.isPresent()) { if (!optionalCache.isPresent()) {
return ResponseEntity.status(404).body(new Gson().toJson("There is no cache with the ID " + cacheID)); return ResponseEntity.status(404).body(new Gson().toJson("Es gab einen Fehler beim Löschen des Caches"));
} }
Cache cache = optionalCache.get(); Cache cache = optionalCache.get();