first implementation for checkStation(API method for cache durchführen)
This commit is contained in:
parent
43caf76471
commit
0f856b1ec2
@ -164,6 +164,81 @@ public class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@RequestMapping("/api/checkStation")
|
||||
@ResponseBody
|
||||
public ResponseEntity checkStation(@RequestParam String token,
|
||||
@RequestParam String cacheID,
|
||||
@RequestParam String stationID,
|
||||
@RequestParam String durchgefuehrterCacheID) {
|
||||
try {
|
||||
Claims claims = Jwts.parser() //Parse JWT
|
||||
.setSigningKey(key)
|
||||
.parseClaimsJws(token).getBody();
|
||||
|
||||
User user = userRepository.findByUsername(claims.getSubject());
|
||||
if (user == null) {
|
||||
return ResponseEntity.status(404).body("User was not found");
|
||||
}
|
||||
|
||||
Optional<Cache> cacheOptional = cacheRepository.findById(Integer.valueOf(cacheID));
|
||||
Cache cache;
|
||||
if (cacheOptional.isPresent()) {
|
||||
cache = cacheOptional.get();
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID);
|
||||
}
|
||||
|
||||
Optional<Cache> durchgefuehrterCacheIDOptional = cacheRepository.findById(Integer.valueOf(durchgefuehrterCacheID));
|
||||
Cache durchgefuehrterCache;
|
||||
if (durchgefuehrterCacheIDOptional.isPresent()) {
|
||||
durchgefuehrterCache = cacheOptional.get();
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Cache " + durchgefuehrterCacheID);
|
||||
}
|
||||
|
||||
Optional<Station> stationOptional = stationRepository.findById(Integer.valueOf(stationID));
|
||||
Station station;
|
||||
if (stationOptional.isPresent()) {
|
||||
station = stationOptional.get();
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Station " + stationID);
|
||||
}
|
||||
|
||||
if (cache != durchgefuehrterCache) {
|
||||
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station");
|
||||
}
|
||||
|
||||
Bearbeitet bearbeitet;
|
||||
if (bearbeitetRepository.findByUserAndCache(user, cache) != null) {
|
||||
bearbeitet = bearbeitetRepository.findByUserAndCache(user, cache);
|
||||
} else {
|
||||
return ResponseEntity.status(400).body("The user has not started this cache yet");
|
||||
}
|
||||
|
||||
Station aktuelleStation = bearbeitet.getAktuelleStation();
|
||||
|
||||
int i = 0;
|
||||
for (Station station1 : cache.getStationen()) {
|
||||
if (station1.equals(station)) {
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (cache.getStationen().get(i - 1).equals(aktuelleStation)) {
|
||||
return ResponseEntity.status(200).body("OK");
|
||||
} else {
|
||||
return ResponseEntity.status(400).body("The scanned station isn´t the correct following station");
|
||||
}
|
||||
|
||||
} catch (ExpiredJwtException e) {
|
||||
return ResponseEntity.status(400).body("JWT Token expired");
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(400).body("JWT Token invalid");
|
||||
}
|
||||
}
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@RequestMapping("/api/createCache")
|
||||
@ResponseBody
|
||||
|
||||
Loading…
Reference in New Issue
Block a user