fixed a bug with deleteCache
This commit is contained in:
parent
9828f88f7b
commit
16cae0ba90
@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.xml.bind.DatatypeConverter;
|
||||
import java.lang.reflect.Array;
|
||||
import java.security.Key;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.*;
|
||||
@ -136,34 +137,34 @@ public class Controller {
|
||||
if (cacheOptional.isPresent()) {
|
||||
Cache cache = cacheOptional.get();
|
||||
|
||||
if(bearbeitetRepository.findByUserAndCache(user, cache) != null){
|
||||
if (bearbeitetRepository.findByUserAndCache(user, cache) != null) {
|
||||
Bearbeitet bearbeitet1 = bearbeitetRepository.findByUserAndCache(user, cache);
|
||||
return ResponseEntity.status(200).body(bearbeitet1);
|
||||
}
|
||||
|
||||
bearbeitet.setCache(cache);
|
||||
|
||||
Station startStation = cache.getStationen().get(0);
|
||||
bearbeitet.setAktuelleStation(startStation);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID);
|
||||
}
|
||||
Station startStation = cache.getStationen().get(0);
|
||||
bearbeitet.setAktuelleStation(startStation);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("Couldnt find Cache " + cacheID);
|
||||
}
|
||||
|
||||
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional =
|
||||
cacheAccesDefinitionRepository.findById(0); // angefangen
|
||||
if (cacheAccesDefinitionOptional.isPresent()) {
|
||||
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
|
||||
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0);
|
||||
}
|
||||
Optional<CacheAccesDefinition> cacheAccesDefinitionOptional =
|
||||
cacheAccesDefinitionRepository.findById(0); // angefangen
|
||||
if (cacheAccesDefinitionOptional.isPresent()) {
|
||||
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
|
||||
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
||||
} else {
|
||||
return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0);
|
||||
}
|
||||
|
||||
bearbeitetRepository.save(bearbeitet);
|
||||
|
||||
return ResponseEntity.status(201).body(new Gson().toJson(bearbeitet));
|
||||
} catch (ExpiredJwtException e) {
|
||||
return ResponseEntity.status(400).body("JWT Token expired");
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(400).body("JWT Token invalid");
|
||||
}
|
||||
|
||||
@ -201,7 +202,7 @@ public class Controller {
|
||||
public ResponseEntity createCache(@RequestBody Cache cache) {
|
||||
System.out.println(cache.getName());
|
||||
System.out.println(cache.getStationen().size());
|
||||
System.out.println(cache.getStationen().get(0).getId());
|
||||
// System.out.println(cache.getStationen().get(0).getId());
|
||||
// Stationen werden in die Datenbank eingetragen
|
||||
for (Station station : cache.getStationen()) {
|
||||
ResponseEntity response = createStation(station);
|
||||
@ -292,9 +293,9 @@ public class Controller {
|
||||
.parseClaimsJws(token).getBody();
|
||||
|
||||
return ResponseEntity.status(200).body(claims.get("admin"));
|
||||
}catch (ExpiredJwtException e) {
|
||||
} catch (ExpiredJwtException e) {
|
||||
return ResponseEntity.status(400).body("JWT Token expired");
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(400).body("JWT Token invalid");
|
||||
}
|
||||
|
||||
@ -335,12 +336,18 @@ public class Controller {
|
||||
}
|
||||
}
|
||||
|
||||
for(Station station : cache.getStationen()) {
|
||||
stationRepository.delete(station);
|
||||
ArrayList<Station> stationen = new ArrayList<>();
|
||||
for (Station station : cache.getStationen()) {
|
||||
stationen.add(stationRepository.findById(station.getId()).get());
|
||||
}
|
||||
|
||||
cacheRepository.delete(cache);
|
||||
|
||||
for (Station station : stationen) {
|
||||
stationRepository.delete(station);
|
||||
}
|
||||
|
||||
|
||||
return ResponseEntity.status(200).body(new Gson().toJson(true));
|
||||
}
|
||||
|
||||
@ -371,7 +378,7 @@ public class Controller {
|
||||
}
|
||||
} catch (ExpiredJwtException e) {
|
||||
return ResponseEntity.status(400).body("JWT Token expired");
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(400).body("JWT Token invalid");
|
||||
}
|
||||
}
|
||||
@ -412,7 +419,7 @@ public class Controller {
|
||||
}
|
||||
} catch (ExpiredJwtException e) {
|
||||
return ResponseEntity.status(400).body("JWT Token expired");
|
||||
} catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return ResponseEntity.status(400).body("JWT Token invalid");
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user