예제 #1
1
  @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;
  }
예제 #2
0
  @RequestMapping(value = "", method = RequestMethod.GET)
  @ApiOperation(
      value = "Get All LunchMenus.",
      notes = "Returns list of all existed LunchMenus by page.")
  @ApiResponses(
      value = {
        @ApiResponse(code = 401, message = "Only authenticated access allowed."),
      })
  public Page<LunchMenu> getAllLunchMenus(
      @RequestParam(value = "page", required = true, defaultValue = DEFAULT_PAGE_NUM)
          @ApiParam(value = "Page number of LunchMenus list", required = false)
          Integer page,
      @ApiParam(
              value = "Size of Page of LunchMenus list. ",
              allowableValues = "range[1,1000]",
              required = false)
          @RequestParam(value = "size", required = true, defaultValue = DEFAULT_PAGE_SIZE)
          Integer size,
      @ApiParam(value = "", hidden = true) Authentication authentication) {
    SpringUser springUser = (SpringUser) authentication.getPrincipal();
    LOGGER.debug(
        "Get all LunchMenu on page {} with size {} by {}", page, size, springUser.getUsername());

    size = Math.min(1000, size);
    return lunchMenusService.getAllLunchMenus(page, size, springUser.getRole());
  }
예제 #3
0
 @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)));
 }