Merge branch 'develop' into frontend/timo
This commit is contained in:
commit
48b3be41aa
@ -109,8 +109,8 @@ public class Controller {
|
|||||||
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
|
CacheAccesDefinition cacheAccesDefinition = cacheAccesDefinitionOptional.get();
|
||||||
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
bearbeitet.setCacheAccesDefinition(cacheAccesDefinition);
|
||||||
} else {
|
} else {
|
||||||
throw new IllegalParameterException("There is no cacheAccesDefinition with the ID " + 0);
|
return ResponseEntity.status(404).body("There is no cacheAccesDefinition with the ID " + 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
bearbeitetRepository.save(bearbeitet);
|
bearbeitetRepository.save(bearbeitet);
|
||||||
|
|
||||||
@ -130,7 +130,7 @@ public class Controller {
|
|||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/logout")
|
@RequestMapping("/api/logout")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity logout(@RequestParam String token) {
|
public ResponseEntity logout(@RequestParam String token) {
|
||||||
// System.out.println("logout");
|
// System.out.println("logout");
|
||||||
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
||||||
// System.out.println(token);
|
// System.out.println(token);
|
||||||
@ -146,12 +146,12 @@ public class Controller {
|
|||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/createStation")
|
@RequestMapping("/api/createStation")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity createStation(@RequestParam String description,
|
public ResponseEntity createStation(@RequestParam String description,
|
||||||
@RequestParam String lattitude,
|
@RequestParam String latitude,
|
||||||
@RequestParam String longitude,
|
@RequestParam String longitude,
|
||||||
@RequestParam String solution) throws IllegalParameterException {
|
@RequestParam String solution) {
|
||||||
|
|
||||||
if (description.length() == 0 || lattitude.length() == 0 || longitude.length() == 0 || solution.length() == 0) {
|
if (description.length() == 0 || latitude.length() == 0 || longitude.length() == 0 || solution.length() == 0) {
|
||||||
return ResponseEntity.status(400).body("At least one Argument was empty");
|
return ResponseEntity.status(400).body("At least one Argument was empty");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -159,9 +159,9 @@ public class Controller {
|
|||||||
double longi;
|
double longi;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
latti = Double.valueOf(lattitude);
|
latti = Double.valueOf(latitude);
|
||||||
if (latti < -90 || latti > 90) {
|
if (latti < -90 || latti > 90) {
|
||||||
return ResponseEntity.status(400).body("Lattitude has to be between -90 and 90 Degree");
|
return ResponseEntity.status(400).body("Latitude has to be between -90 and 90 Degree");
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
return ResponseEntity.status(400).body("Latitude has to be a decimal");
|
return ResponseEntity.status(400).body("Latitude has to be a decimal");
|
||||||
@ -196,8 +196,11 @@ public class Controller {
|
|||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/checkAdmin")
|
@RequestMapping("/api/checkAdmin")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity checkAdmin(@RequestParam String token) {
|
public ResponseEntity checkAdmin(@RequestParam String token) {
|
||||||
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
||||||
|
if(user == null){
|
||||||
|
return ResponseEntity.status(404).body("User was not found");
|
||||||
|
}
|
||||||
for (Role role : user.getRoles()) {
|
for (Role role : user.getRoles()) {
|
||||||
if (role.getId() == 0) { // is admin
|
if (role.getId() == 0) { // is admin
|
||||||
return ResponseEntity.status(200).body("User is Admin");
|
return ResponseEntity.status(200).body("User is Admin");
|
||||||
@ -210,18 +213,18 @@ public class Controller {
|
|||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/getAllStations")
|
@RequestMapping("/api/getAllStations")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity getAllStations() {
|
public ResponseEntity getAllStations() {
|
||||||
return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll()));
|
return ResponseEntity.status(200).body(new Gson().toJson(stationRepository.findAll()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/createCache")
|
@RequestMapping("/api/createCache")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity createCache(@RequestParam String description,
|
public ResponseEntity createCache(@RequestParam String description,
|
||||||
@RequestParam String name,
|
@RequestParam String name,
|
||||||
@RequestParam String rankingPoints,
|
@RequestParam String rankingPoints,
|
||||||
@RequestParam(value = "rewardID", defaultValue = "-1") String rewardID,
|
@RequestParam(value = "rewardID", defaultValue = "-1") String rewardID,
|
||||||
@RequestParam List<Station> stationen) throws IllegalParameterException {
|
@RequestParam List<Station> stationen) {
|
||||||
|
|
||||||
if (description.length() == 0 || name.length() == 0 || rankingPoints.length() == 0 || stationen.size() == 0) {
|
if (description.length() == 0 || name.length() == 0 || rankingPoints.length() == 0 || stationen.size() == 0) {
|
||||||
return ResponseEntity.status(400).body("Fields can´t be empty");
|
return ResponseEntity.status(400).body("Fields can´t be empty");
|
||||||
@ -271,7 +274,7 @@ public class Controller {
|
|||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/deleteCache")
|
@RequestMapping("/api/deleteCache")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity deleteCache(@RequestParam String cacheID) {
|
public ResponseEntity deleteCache(@RequestParam String cacheID) {
|
||||||
Optional<Cache> optionalCache = cacheRepository.findById(Integer.valueOf(cacheID));
|
Optional<Cache> optionalCache = cacheRepository.findById(Integer.valueOf(cacheID));
|
||||||
if (!optionalCache.isPresent()) {
|
if (!optionalCache.isPresent()) {
|
||||||
return ResponseEntity.status(404).body(new Gson().toJson("There is no cache with the ID " + cacheID));
|
return ResponseEntity.status(404).body(new Gson().toJson("There is no cache with the ID " + cacheID));
|
||||||
@ -299,7 +302,7 @@ public class Controller {
|
|||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/getMyCaches")
|
@RequestMapping("/api/getMyCaches")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity getMyCaches(@RequestParam String token) {
|
public ResponseEntity getMyCaches(@RequestParam String token) {
|
||||||
try {
|
try {
|
||||||
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
@ -322,14 +325,14 @@ public class Controller {
|
|||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/getRankingList")
|
@RequestMapping("/api/getRankingList")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity getRankingList() {
|
public ResponseEntity getRankingList() {
|
||||||
return ResponseEntity.status(200).body(new Gson().toJson(userRepository.getRankingList()));
|
return ResponseEntity.status(200).body(new Gson().toJson(userRepository.getRankingList()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
|
||||||
@RequestMapping("/api/getUser")
|
@RequestMapping("/api/getUser")
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
ResponseEntity getUser(@RequestParam String token) {
|
public ResponseEntity getUser(@RequestParam String token) {
|
||||||
try {
|
try {
|
||||||
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user