Merge branch 'develop' into frontend/timo

This commit is contained in:
Maximilian Leopold 2019-05-13 11:28:24 +02:00
commit ac99234c51

View File

@ -324,6 +324,39 @@ public class Controller {
return createCacheUtil(cache);
}
@ApiOperation(value = "Edits a Cache")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ApiResponse(code = 401, message = "JWT Token expired"),
@ApiResponse(code = 400, message = "Something wrong with the given Parameters")
})
@CrossOrigin(origins = "*", allowedHeaders = "*") // only for dev purpose
@RequestMapping(value = "/api/editCache", method = RequestMethod.PUT, produces = "application/json")
@ResponseBody
public ResponseEntity editCache(@RequestBody Cache newCache){
//----------------------
//Get Cache
ResponseEntity getCache = FinderUtil.findCacheById(newCache.getId() + "");
if (getCache.getStatusCodeValue() != 200) {
return getCache;
}
Cache oldCache = (Cache) getCache.getBody();
//----------------------
oldCache.setDescription(newCache.getDescription());
oldCache.setName(newCache.getName());
oldCache.setRankingPoints(newCache.getRankingPoints());
oldCache.setReward(newCache.getReward());
oldCache.setStationen(newCache.getStationen());
cacheRepository.save(oldCache);
return ResponseEntity.status(200).body("Cache edited");
}
@ApiOperation(value = "Checks if the given User has an admin role")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "Database error"),
@ -673,16 +706,17 @@ public class Controller {
// verlässt team
user_info.setTeam(null);
int i = 0;
//int i = 0;
// zählt teammitglieder
for (User_Info userInfo1 : user_infoRepository.findAll()) {
List<User_Info> user_infos = user_infoRepository.findByTeam(team);
/*for (User_Info userInfo1 : user_infoRepository.findAll()) {
if (userInfo1.getTeam().equals(team)) {
i++;
}
}
}*/
// löscht team, wenn keine teammitglieder mehr vorhanden
if (i == 0) {
if (user_infos.size() == 0) {
teamRepository.delete(team);
}