package sg.ncl.service.user.web;

import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PathVariable;
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.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
import sg.ncl.service.user.domain.User;
import sg.ncl.service.user.logic.UserService;

import javax.inject.Inject;
import java.util.List;

/**
 * @author Christopher Zhong
 */
@RestController
@RequestMapping(path = "/users", produces = MediaType.APPLICATION_JSON_VALUE)
public class UsersController {

    private final UserService userService;

    @Inject
    protected UsersController(final UserService userService) {
        this.userService = userService;
    }

    @RequestMapping(method = RequestMethod.GET)
    @ResponseStatus(code = HttpStatus.OK)
    public List<User> get() {
        return userService.getAll();
    }

    @RequestMapping(path = "/{id}", method = RequestMethod.GET)
    @ResponseStatus(code = HttpStatus.OK)
    public User getUser(@PathVariable String id) {
        return userService.findUser(id);
    }

    @RequestMapping(path = "/{id}", method = RequestMethod.PUT)
    @ResponseStatus(code = HttpStatus.ACCEPTED)
    public void updateUser(@PathVariable String id, @RequestBody User user) {
        userService.updateUser(id, user);
    }

    @RequestMapping(path = "/addUserToTeam/{id}/{teamId}", method = RequestMethod.POST)
    @ResponseStatus(value = HttpStatus.OK)
    public void addUserToTeam(@PathVariable String id, @PathVariable String teamId) {
        userService.addTeam(id, teamId);
    }

}

@@ -1614,16 +1614,13 @@
 id%7D/
-%7B
 team
-Id%7D
+s
 %22, m
@@ -1709,22 +1709,16 @@
 void add
-UserTo
 Team(@Pa
@@ -1744,34 +1744,29 @@
 d, @
-PathVariable String teamId
+RequestBody User user
 ) %7B%0A
@@ -1801,14 +1801,30 @@
 id, 
-teamId
+user.getTeams().get(0)
 );%0A 

refactor UserService addUserToTeam to addTeam and change parameters to RequestBody User