added deleteCache API and fixed some mistakes in other methods
This commit is contained in:
parent
baab96059b
commit
8fad8e427e
@ -39,6 +39,9 @@ public class Controller {
|
||||
@Autowired
|
||||
UserRepository userRepository;
|
||||
|
||||
@Autowired
|
||||
StationReihenfolgeRepository stationReihenfolgeRepository;
|
||||
|
||||
private AtomicLong counter = new AtomicLong();
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@ -249,9 +252,39 @@ public class Controller {
|
||||
stationReihenfolge.setCache(cache);
|
||||
stationReihenfolge.setStation(stationen.get(i));
|
||||
stationReihenfolge.setNachfolgeStation(stationen.get(i + 1));
|
||||
stationReihenfolgeRepository.save(stationReihenfolge);
|
||||
}
|
||||
|
||||
return new Gson().toJson(cache);
|
||||
}
|
||||
|
||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||
@RequestMapping("/api/deleteCache")
|
||||
@ResponseBody
|
||||
boolean deleteCache(@RequestParam String cacheID) throws IllegalParameterException {
|
||||
Optional<Cache> optionalCache = cacheRepository.findById(Integer.valueOf(cacheID));
|
||||
if (!optionalCache.isPresent()) {
|
||||
throw new IllegalParameterException("There is no cache with the ID " + cacheID);
|
||||
}
|
||||
|
||||
Cache cache = optionalCache.get();
|
||||
|
||||
for (StationReihenfolge stationReihenfolge : stationReihenfolgeRepository.findAll()) {
|
||||
if (stationReihenfolge.getCache().getId() == cache.getId()) {
|
||||
stationReihenfolgeRepository.delete(stationReihenfolge);
|
||||
}
|
||||
}
|
||||
|
||||
for (Bearbeitet bearbeitet : bearbeitetRepository.findAll()) {
|
||||
if (bearbeitet.getCache().getId() == cache.getId()) {
|
||||
bearbeitetRepository.delete(bearbeitet);
|
||||
}
|
||||
}
|
||||
|
||||
cacheRepository.delete(cache);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user