fehlermeldungen vereinfacht
This commit is contained in:
parent
0aff9266d6
commit
99f9748de3
@ -45,12 +45,14 @@ public class CacheConstructionUtil {
|
||||
public static ResponseEntity createCacheUtil(Cache cache) {
|
||||
|
||||
// Stationen werden in die Datenbank eingetragen
|
||||
int position = 1;
|
||||
for (Station station : cache.getStationen()) {
|
||||
ResponseEntity response = createStationUtil(station);
|
||||
ResponseEntity response = createStationUtil(station, position);
|
||||
if (response.getStatusCodeValue() == 400) {
|
||||
deleteStationenUtil(cache);
|
||||
return response;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
|
||||
// Caches werden in die Datenbank eingetragen
|
||||
@ -81,18 +83,19 @@ public class CacheConstructionUtil {
|
||||
return ResponseEntity.status(200).body(new Gson().toJson(cache));
|
||||
}
|
||||
|
||||
public static ResponseEntity createStationUtil(Station station) {
|
||||
public static ResponseEntity createStationUtil(Station station, int position) {
|
||||
|
||||
if (station.getDescription().length() == 0 /*|| station.getSolution().length() == 0*/) {
|
||||
return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
|
||||
}
|
||||
|
||||
if (station.getLattitude() < 49 || station.getLattitude() > 50) {
|
||||
return ResponseEntity.status(400).body("Der Breitengrad einer Station ist außerhalb der Bundesgartenschau");
|
||||
|
||||
return ResponseEntity.status(400).body("Der Breitengrad der Station " + position + " ist außerhalb der Bundesgartenschau. Dieser muss zwischen 49 und 50 liegen.");
|
||||
}
|
||||
|
||||
if (station.getLongitude() < 9 || station.getLongitude() > 10) {
|
||||
return ResponseEntity.status(400).body("Der Längengrad einer Station ist außerhalb der Bundesgartenschau");
|
||||
return ResponseEntity.status(400).body("Der Längengrad der Station " + position + " ist außerhalb der Bundesgartenschau. Dieser muss zwischen 9 und 10 liegen.");
|
||||
}
|
||||
|
||||
Random r = new Random();
|
||||
@ -135,12 +138,13 @@ public class CacheConstructionUtil {
|
||||
|
||||
ResponseEntity response = new ResponseEntity(HttpStatus.ACCEPTED);
|
||||
List<Station> newCreatedStationList = new ArrayList<Station>();
|
||||
int position = 1;
|
||||
for (Station station : cache.getStationen()) {
|
||||
boolean stationIsNew = true;
|
||||
for (Station oldStation : oldCache.getStationen()) {
|
||||
// wenn Station schon vorher vorhanden war, wird diese mit den neuen Daten geupdatet
|
||||
if (oldStation.getId() == station.getId()) {
|
||||
response = createStationUtil(station);
|
||||
response = createStationUtil(station, position);
|
||||
stationIsNew = false;
|
||||
break;
|
||||
}
|
||||
@ -148,7 +152,7 @@ public class CacheConstructionUtil {
|
||||
|
||||
// wenn Station neu hinzugefügt wurde, wirdcd die Station zusätzlich in die Datenbank gespeichert
|
||||
if (stationIsNew) {
|
||||
response = createStationUtil(station);
|
||||
response = createStationUtil(station, position);
|
||||
if (response.getStatusCodeValue() == 200) {
|
||||
newCreatedStationList.add(station);
|
||||
}
|
||||
@ -163,6 +167,7 @@ public class CacheConstructionUtil {
|
||||
deleteNewCreatedStationsUtil(newCreatedStationList);
|
||||
return response;
|
||||
}
|
||||
position++;
|
||||
}
|
||||
|
||||
// überprüft den Cache nach validen Daten
|
||||
|
||||
Loading…
Reference in New Issue
Block a user