package com.addicks.sendash.admin.api.rest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import com.addicks.sendash.admin.domain.User;
import com.addicks.sendash.admin.service.IUserService;
import com.wordnik.swagger.annotations.Api;
import com.wordnik.swagger.annotations.ApiOperation;
import com.wordnik.swagger.annotations.ApiParam;

@RestController
@RequestMapping(value = UserController.REQUEST_MAPPING)
@Api(value = "user", description = "CRUD user management.")
public class UserController extends AbstractRestHandler {

  public static final String REQUEST_MAPPING = "/user";

  private static final Logger log = LoggerFactory.getLogger(UserController.class);

  @Autowired
  private IUserService userService;

  public UserController() {

  }

  @RequestMapping(value = "", method = RequestMethod.POST, consumes = { "application/json",
      "application/xml" }, produces = { "application/json", "application/xml" })
  @ResponseStatus(HttpStatus.CREATED)
  @ApiOperation(value = "Create a user.", notes = "Returns the URL of the new user in the Location header.")
  public void createHotel(@RequestBody User user, HttpServletRequest request,
      HttpServletResponse response) {
    User savedUser = userService.save(user);
    response.setHeader("Location",
        request.getRequestURL().append("/").append(savedUser.getId()).toString());
  }

  @RequestMapping(value = "", method = RequestMethod.GET, produces = { "application/json",
      "application/xml" })
  @ResponseStatus(HttpStatus.OK)
  @ApiOperation(value = "Get a paginated list of all users.", notes = "The list is paginated. You can provide a page number (default 0) and a page size (default 100)")
  public @ResponseBody Page<User> getAllUsers(
      @ApiParam(value = "The page number (zero-based)", required = true) @RequestParam(value = "page", required = true, defaultValue = DEFAULT_PAGE_NUM) Integer page,
      @ApiParam(value = "Tha page size", required = true) @RequestParam(value = "size", required = true, defaultValue = DEFAULT_PAGE_SIZE) Integer size,
      HttpServletRequest request, HttpServletResponse response) {

    log.error("Returning: " + userService.getAllUsers(page, size));
    return userService.getAllUsers(page, size);
  }
}
@@ -2505,16 +2505,17 @@
 alue = %22
+_
 page%22, r
@@ -2658,19 +2658,23 @@
 alue = %22
-siz
+_perPag
 e%22, requ
@@ -2809,33 +2809,29 @@
     
-log.error(%22Returning: %22 +
+Page%3CUser%3E userPage =
  use
@@ -2862,16 +2862,158 @@
 e, size)
+;%0A    log.error(%22content: %22 + userPage.getContent());%0A    log.error(%22size:%22 + userPage.getTotalElements());%0A    log.error(%22Returning: %22 + page
 );%0A    r

add view all users.