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
This commit is contained in:
Michael 2019-04-16 10:17:36 +02:00
parent 663d3482ee
commit 4b16b6a2b1
2 changed files with 24 additions and 17 deletions

View File

@ -279,16 +279,18 @@ public class Controller {
if (cache.getStationen().get(i - 1).equals(aktuelleStation)) { if (cache.getStationen().get(i - 1).equals(aktuelleStation)) {
bearbeitet.setAktuelleStation(station); bearbeitet.setAktuelleStation(station);
if (i == cache.getStationen().size() - 1) { // letze Station erreicht if (i == cache.getStationen().size() - 1) { // letze Station erreicht
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional = //----------------------
cacheAccesDefinitionRepository.findById(1); // abgeschlossen //Get CacheAccesDefinition
if (cacheAccesDefinitionOptional.isPresent()) { ResponseEntity getCacheAccesDefinition = FinderUtil.findCacheAccesDefinitionById("1");
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition); if (getCacheAccesDefinition.getStatusCodeValue() != 200) {
} else { return getCacheAccesDefinition;
return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 1);
} }
CacheAccesDefinition cacheAccesDefinition = (CacheAccesDefinition) getCacheAccesDefinition.getBody();
//----------------------
} }
return ResponseEntity.status(200).body(new Gson().toJson(station)); return ResponseEntity.status(200).body(new Gson().toJson(bearbeitet));
} else { } else {
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station"); return ResponseEntity.status(400).body("The scanned station isn´t the correct following station");
} }

View File

@ -1,9 +1,6 @@
package hhn.labsw.bugageocaching.util; package hhn.labsw.bugageocaching.util;
import hhn.labsw.bugageocaching.entities.Bearbeitet; import hhn.labsw.bugageocaching.entities.*;
import hhn.labsw.bugageocaching.entities.Cache;
import hhn.labsw.bugageocaching.entities.Station;
import hhn.labsw.bugageocaching.entities.User;
import hhn.labsw.bugageocaching.repositories.*; import hhn.labsw.bugageocaching.repositories.*;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
@ -74,4 +71,12 @@ public class FinderUtil {
return ResponseEntity.status(404).body("Couldnt find user with username " + username); return ResponseEntity.status(404).body("Couldnt find user with username " + username);
} }
public static ResponseEntity findCacheAccesDefinitionById(String cacheAccesDefinitionID) {
Optional<CacheAccesDefinition> 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);
}
}
} }