package com.feiyangedu.springcloud.petstore.account.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.feiyangedu.springcloud.petstore.account.bean.UserBean;
import com.feiyangedu.springcloud.petstore.account.domain.User;
import com.feiyangedu.springcloud.petstore.account.repository.UserRepository;
import com.feiyangedu.springcloud.petstore.common.service.AbstractService;
import com.feiyangedu.springcloud.petstore.common.util.BeanUtil;

@RestController
public class AccountService extends AbstractService {

	@Autowired
	UserRepository userRepository;

	/**
	 * Get all users.
	 * 
	 * @param pageIndex
	 */
	@GetMapping("/api/users")
	public Page<User> getUsers(@RequestParam(value = "page", defaultValue = "0") int pageIndex) {
		return userRepository.findAll(new PageRequest(pageIndex, DEFAULT_PAGE_SIZE,
				new Sort(new Sort.Order(Sort.Direction.DESC, "createdAt"))));
	}

	@GetMapping("/api/users/{id}")
	public User getUser(@PathVariable("id") String id) {
		return checkNonNull(userRepository.findOne(id));
	}

	@PostMapping("/api/users2")
	public User createUser2(@RequestParam("aa") java.time.LocalDateTime aa, @RequestBody UserBean bean) {
		User user = new User();
		BeanUtil.copyPublicFields(bean, user);
		userRepository.save(user);
		return user;
	}

	@PostMapping("/api/users")
	public User createUser(@RequestBody UserBean bean) {
		User user = new User();
		BeanUtil.copyPublicFields(bean, user);
		userRepository.save(user);
		return user;
	}
}

@@ -500,16 +500,79 @@
 stBody;%0A
+import org.springframework.web.bind.annotation.RequestMapping;%0A
 import o
@@ -624,16 +624,16 @@
 tParam;%0A
-
 import o
@@ -1053,16 +1053,48 @@
 troller%0A
+@RequestMapping(%22/api/account%22)%0A
 public c
@@ -1247,36 +1247,32 @@
 %0A%09@GetMapping(%22/
-api/
 users%22)%0A%09public 
@@ -1517,28 +1517,24 @@
 etMapping(%22/
-api/
 users/%7Bid%7D%22)
@@ -1639,24 +1639,24 @@
 e(id));%0A%09%7D%0A%0A
+
 %09@PostMappin
@@ -1663,259 +1663,8 @@
 g(%22/
-api/users2%22)%0A%09public User createUser2(@RequestParam(%22aa%22) java.time.LocalDateTime aa, @RequestBody UserBean bean) %7B%0A%09%09User user = new User();%0A%09%09BeanUtil.copyPublicFields(bean, user);%0A%09%09userRepository.save(user);%0A%09%09return user;%0A%09%7D%0A%0A%09@PostMapping(%22/api/
 user

refactor url