added getUser API method

This commit is contained in:
Michael 2019-04-04 12:16:26 +02:00
parent 61330b3f0b
commit cd3508090b

View File

@ -290,7 +290,8 @@ public class Controller {
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/getMyCaches")
@ResponseBody
String getMyCaches(@RequestParam String token) {
ResponseEntity getMyCaches(@RequestParam String token) {
try {
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
ArrayList<Bearbeitet> bearbeitetList = new ArrayList<>();
@ -299,14 +300,29 @@ public class Controller {
bearbeitetList.add(bearbeitet);
}
}
return new Gson().toJson(bearbeitetList);
return ResponseEntity.status(200).body(new Gson().toJson(bearbeitetList));
} catch (Exception e) {
return ResponseEntity.status(404).body("User was not found in the database");
}
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/getRankingList")
@ResponseBody
String getRankingList() {
return new Gson().toJson(userRepository.getRankingList());
ResponseEntity getRankingList() {
return ResponseEntity.status(200).body(new Gson().toJson(userRepository.getRankingList()));
}
@CrossOrigin(origins = "http://localhost:8081") // only for dev purpose
@RequestMapping("/api/getUser")
@ResponseBody
ResponseEntity getUser(@RequestParam String token) {
try {
User user = userRepository.findByUsername(token.substring(0, token.indexOf("$")));
return ResponseEntity.status(200).body(new Gson().toJson(user));
} catch (Exception e) {
return ResponseEntity.status(404).body("User was not found in the database");
}
}
}