@ApiOperation( value = "UnVote for LunchMenu.", notes = "Returns NO_CONTENT if unVoting was successful.") @ApiResponses( value = { @ApiResponse(code = 401, message = "Only authenticated access allowed."), @ApiResponse(code = 403, message = "Only user of ADMIN role can have access to it."), @ApiResponse(code = 404, message = "LunchMenu with such Id not found."), }) @RequestMapping(value = "/{id}/unvote", method = RequestMethod.POST) public Long unVote( @ApiParam(value = "ID of LunchMenu from DB", required = true) @PathVariable Long id, @ApiParam(value = "authentication ", hidden = true) Authentication authentication) { SpringUser springUser = (SpringUser) authentication.getPrincipal(); LOGGER.debug("Voting on LunchMenu (id={}) by {}", id, springUser.getUsername()); Optional<LunchMenu> menuSearch = lunchMenusService.getLunchMenuById(id, springUser.getRole()); menuSearch.orElseThrow( () -> new ExceptionLunchMenuNotFound(String.format("LunchMenu=%s not found.", id))); Optional<User> userSearch = usersService.getUserById(springUser.getId()); userSearch.orElseThrow( () -> new UsersController.ExceptionUserNotFound(String.format("User=%s not found.", id))); Long result = voteService.unVote(menuSearch.get(), userSearch.get()); return result; }
@ApiOperation( value = "Find LunchMenu by ID.", notes = "Returns a LunchMenu if found it.", response = Restaurant.class) @ApiResponses( value = { @ApiResponse(code = 401, message = "Only authenticated access allowed."), @ApiResponse(code = 404, message = "LunchMenu with such Id not found.") }) @RequestMapping(value = "/{id}", method = RequestMethod.GET) public LunchMenu getLunchMenu( @ApiParam(value = "ID of LunchMenu from DB", required = true) @PathVariable Long id, @ApiParam(value = "authentication", hidden = true) Authentication authentication) throws ExceptionLunchMenuNotFound { SpringUser springUser = (SpringUser) authentication.getPrincipal(); LOGGER.debug("Get LunchMenu (id={}) by {}", id, springUser.getUsername()); return lunchMenusService .getLunchMenuById(id, springUser.getRole()) .orElseThrow( () -> new ExceptionLunchMenuNotFound(String.format("LunchMenu=%s not found.", id))); }