Пример #1
0
  @RequestMapping(value = "/player/{id}", method = RequestMethod.DELETE)
  public ResponseEntity<Player> deletePlayer(@PathVariable("id") long id) {
    logger.info(String.format("Fetching & deleting player with id %d.", id));

    Player player = playerService.findPlayer(id);
    if (player == null) {
      logger.info(String.format("Unable to delete. Player with id %d not found.", id));
      return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
    playerService.deletePlayer(id);
    return new ResponseEntity<>(HttpStatus.NO_CONTENT);
  }
Пример #2
0
 @RequestMapping(value = "player", method = RequestMethod.POST)
 public ResponseEntity<Void> createPlayer(
     @RequestBody Player player, UriComponentsBuilder ucBuilder) {
   logger.info(String.format("Creating player %s", player));
   if (playerService.exists(player)) {
     logger.info(String.format("Player exists | %s", player));
     return new ResponseEntity<>(HttpStatus.CONFLICT);
   }
   playerService.createPlayer(player);
   HttpHeaders headers = new HttpHeaders();
   headers.setLocation(ucBuilder.path("/player/{id}").buildAndExpand(player.getId()).toUri());
   return new ResponseEntity<>(headers, HttpStatus.CREATED);
 }
Пример #3
0
  @RequestMapping(value = "/player/{id}", method = RequestMethod.PUT)
  public ResponseEntity<Player> updatePlayer(
      @PathVariable("id") long id, @RequestBody Player player) {
    logger.info(String.format("Updating player with id %d.", id));

    Player currentPlayer = playerService.findPlayer(id);
    if (currentPlayer == null) {
      logger.info(String.format("Unable to update. Player with id %d not found.", id));
      return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
    currentPlayer.setName(player.getName());
    playerService.updatePlayer(currentPlayer);
    return new ResponseEntity<>(currentPlayer, HttpStatus.OK);
  }
Пример #4
0
 @RequestMapping(value = "player/{id}", method = RequestMethod.GET)
 public ResponseEntity<Player> getPlayer(@PathVariable long id) {
   logger.info(String.format("Retrieving player %d", id));
   Player player = playerService.findPlayer(id);
   if (player == null) {
     logger.info(String.format("Player %d does not exist", id));
     new ResponseEntity<>(HttpStatus.NOT_FOUND);
   }
   return new ResponseEntity<>(player, HttpStatus.OK);
 }
Пример #5
0
 @RequestMapping(value = "player", method = RequestMethod.GET)
 public ResponseEntity<List<Player>> getAll() {
   logger.info("Retrieving all players");
   List<Player> players = playerService.findAll();
   if (players.isEmpty()) {
     logger.info("There is no players");
     return new ResponseEntity<>(HttpStatus.NO_CONTENT);
   }
   return new ResponseEntity<>(players, HttpStatus.OK);
 }