use of exceptions.IncorrectIdException in project server by sopra-fs22-group-01.
the class UserController method updateReadyStatus.
// Maps data from ready-status changes
// used to flip the ready-status
@PutMapping("/lobbies/{lobbyId}/users/{userId}")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ResponseBody
public void updateReadyStatus(@PathVariable long lobbyId, @PathVariable long userId) {
String baseErrorMessage1 = "No lobby with this id could be found.";
try {
// throws exception if userid doesnt exist
User user = userService.findUserById(userId);
// doesn't update the user in the array of the lobby, only the user in the database
userService.updateUserReadyStatus(user);
// updates the user in the array of the lobby, not the perfect solution
gameService.updateUserReadyStatus(lobbyId, userId);
} catch (IncorrectIdException e1) {
throw new ResponseStatusException(HttpStatus.CONFLICT, baseErrorMessage1);
} catch (Exception e) {
e.printStackTrace();
}
}
use of exceptions.IncorrectIdException in project server by sopra-fs22-group-01.
the class UserController method addUserToLobby.
// ----------------------------MOVED FROM GAMECONTROLLER TO USERCONTROLLER-------------------------------------
// Adds a user to the list of all current players in the lobby
@PostMapping("/lobbies/{lobbyId}/lists/players/{userId}")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ResponseEntity<ArrayList<User>> addUserToLobby(@PathVariable long lobbyId, @PathVariable long userId) {
String baseErrorMessage1 = "No lobby with this id could be found.";
String baseErrorMessage2 = "The same user is already existing in the lobby ";
// gets user from correct user repository
User user = userService.findUserById(userId);
// User userInput = DTOMapper.INSTANCE.convertUserPostDTOtoEntity(userPostDTO);
try {
gameService.addPlayerToLobby(lobbyId, user);
ArrayList<User> allUsers = gameManager.getLobby(lobbyId).getCurrentPlayers();
return ResponseEntity.ok(allUsers);
} catch (IncorrectIdException e1) {
throw new ResponseStatusException(HttpStatus.CONFLICT, baseErrorMessage1);
} catch (Exception e2) {
throw new ResponseStatusException(HttpStatus.CONFLICT, baseErrorMessage2);
}
}
use of exceptions.IncorrectIdException in project server by sopra-fs22-group-01.
the class GameController method deleteUserFromLobby.
// Removes a user from the list of all current players in the lobby
@DeleteMapping("/lobbies/{lobbyId}/players")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public void deleteUserFromLobby(@PathVariable long lobbyId, @RequestBody UserPostDTO userPostDTO) {
String baseErrorMessage1 = "No lobby with this id could be found.";
String baseErrorMessage2 = "No such user exists in the lobby";
User userInput = DTOMapper.INSTANCE.convertUserPostDTOtoEntity(userPostDTO);
try {
gameService.removePlayerFromLobby(lobbyId, userInput);
} catch (IncorrectIdException e1) {
throw new ResponseStatusException(HttpStatus.CONFLICT, baseErrorMessage1);
} catch (Exception e2) {
throw new ResponseStatusException(HttpStatus.NOT_FOUND, baseErrorMessage2);
}
}
use of exceptions.IncorrectIdException in project server by sopra-fs22-group-01.
the class GameController method checkIfMatchCanGetStarted.
// Retrieves if all current players in the lobby are ready or not and if the minimum number of player was reached
@GetMapping("/lobbies/{lobbyId}/status")
@ResponseStatus(HttpStatus.OK)
@ResponseBody
public ResponseEntity<LobbyStatus> checkIfMatchCanGetStarted(@PathVariable long lobbyId) {
String baseErrorMessage1 = "No lobby with this id could be found.";
try {
gameService.checkIfLobbyStatusChanged(lobbyId);
LobbyStatus lobbyStatus = gameService.getLobbyStatus(lobbyId);
return ResponseEntity.ok(lobbyStatus);
} catch (IncorrectIdException e1) {
throw new ResponseStatusException(HttpStatus.CONFLICT, baseErrorMessage1);
}
}
use of exceptions.IncorrectIdException in project Lab5 by Arslanka.
the class RemoveByIdCommand method execute.
@Override
public boolean execute(Object... args) {
try {
collection.removeById((Integer) args[0]);
printer.println("An element whose id field value is equivalent to the specified " + args[0] + " has been successfully removed from the collection", HELP);
printer.println(SEPARATOR, ERROR);
} catch (ArrayIndexOutOfBoundsException e) {
throw new ExecutionException("You have not entered an id to remove from the collection.");
} catch (IncorrectIdException e) {
throw new ExecutionException("Deleting an element by id error.\n" + e.getMessage());
}
return true;
}
Aggregations