package bootwildfly.controllers;

import bootwildfly.models.User;
import bootwildfly.models.repositories.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.List;

@Api(value="account", description="Operations about account")
@RestController
public class AccountController {

	@Autowired
	UserRepository repository;

	@RequestMapping(method = RequestMethod.GET, path="/account", produces = "application/json")
	@ApiOperation(value = "Returns the account info of session user", notes = "Returns the account info of session user")
    public User get(){
		return repository.findAll().get(0);
    }

	@ApiImplicitParams({
        @ApiImplicitParam(
        	name = "name", value = "User's name", required = true, dataType = "string", paramType = "body"),
        @ApiImplicitParam(
            	name = "email", value = "User's email", required = true, dataType = "string", paramType = "body"),
        @ApiImplicitParam(
            	name = "type", value = "User's type (normal|admin)", required = true,
            	dataType = "string", paramType = "body")
      })
	@RequestMapping(method = RequestMethod.POST, path="/account", produces = "application/json")
	@ApiOperation(value = "Saves an user in the system", notes = "Saves an user in the system")
    public String save(){
		return ("{message : 'Account created successfully'}");
    }
}
@@ -27,16 +27,48 @@
 llers;%0A%0A
+import bootwildfly.models.Role;%0A
 import b
@@ -91,16 +91,16 @@
 s.User;%0A
-
 import b
@@ -209,16 +209,76 @@
 owired;%0A
+import org.springframework.web.bind.annotation.RequestBody;%0A
 import o
@@ -657,16 +657,38 @@
 il.List;
+%0Aimport java.util.Map;
 %0A%0A@Api(v
@@ -1057,20 +1057,26 @@
  public 
+List%3C
 User
+%3E
  get()%7B%0A
@@ -1108,15 +1108,8 @@
 ll()
-.get(0)
 ;%0A  
@@ -1790,18 +1790,225 @@
 ng save(
-)%7B
+@RequestBody Map%3CString, String%3E params)%7B%0A%09%09User u = new User();%0A%09%09u.setEmail(params.get(%22email%22));%0A%09%09u.setPassword(params.get(%22password%22));%0A%09%09u.setRole(Role.valueOf(params.get(%22role%22)));%0A%09%09repository.save(u);
 %0A%09%09retur

implement save action