Merge branch 'backend/michael' into backend/max
This commit is contained in:
commit
090e43e7d7
@ -279,16 +279,19 @@ public class Controller {
|
||||
if (cache.getStationen().get(i - 1).equals(aktuelleStation)) {
|
||||
bearbeitet.setAktuelleStation(station);
|
||||
if (i == cache.getStationen().size() - 1) { // letze Station erreicht
|
||||
Optional<CacheAccesDefinition> 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();
|
||||
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
||||
//----------------------
|
||||
}
|
||||
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");
|
||||
}
|
||||
|
||||
@ -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<Station> 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<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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user