package work.zhili.springboot2template.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import work.zhili.springboot2template.core.http.response.Response;
import work.zhili.springboot2template.core.util.UUIDUtils;
import work.zhili.springboot2template.model.User;
import work.zhili.springboot2template.service.IUserService;

/**
 * Title : work.zhili.springboot2template.controller <br>
 * Description :
 *  <p>
 *  <ul> 
 *      <li>
 *  </ul>
 * @author chile
 * @version 1.0
 * @date 2018/5/4 14:27
 */
@RestController
@RequestMapping("/api")
public class UserController {

    private final IUserService userService;

    @Autowired
    public UserController(IUserService userService) {
        this.userService = userService;
    }

    @GetMapping("/v1/users")
    public Object queryAll() {
        return userService.queryAllForTesting();
    }

    @PostMapping("/v1/users")
    public Object add(@RequestParam String username, @RequestParam String password) {
        User user = new User();
        user.setId(UUIDUtils.getUuid());
        user.setUsername(username);
        user.setPassword(password);
        userService.insert(user);
        return Response.SUCCESSFUL_MESSAGE;
    }

    @DeleteMapping("/v1/users")
    public Object delete(String userId) {
        userService.invalid(userId);
        return Response.SUCCESSFUL_MESSAGE;
    }

    @PatchMapping("/v1/users")
    public Object update(@RequestBody User user) {
        userService.update(user);
        return Response.SUCCESSFUL_MESSAGE;
    }

    @GetMapping("/v1/users/{userId}")
    public ResponseEntity<User> select(@PathVariable String userId) {
        User user = userService.select(userId);
        return ResponseEntity.ok(user);
    }
}

@@ -661,19 +661,28 @@
 ng(%22/api
+/v1/users
 %22)%0A
-
 public c
@@ -876,37 +876,24 @@
  @GetMapping
-(%22/v1/users%22)
 %0A    public 
@@ -980,37 +980,24 @@
 @PostMapping
-(%22/v1/users%22)
 %0A    public 
@@ -1315,37 +1315,24 @@
 eleteMapping
-(%22/v1/users%22)
 %0A    public 
@@ -1471,21 +1471,8 @@
 ping
-(%22/v1/users%22)
 %0A   
@@ -1596,32 +1596,32 @@
 MESSAGE;%0A    %7D%0A%0A
+
     @GetMapping(
@@ -1626,17 +1626,8 @@
 g(%22/
-v1/users/
 %7Buse

merge useless url