package com.danchu.momuck.controller;

import com.danchu.momuck.service.AccountService;
import com.danchu.momuck.view.ResultView;
import com.danchu.momuck.vo.Account;
import com.fasterxml.jackson.core.JsonProcessingException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
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.ResponseBody;

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

/**
 * AccountController
 *
 * @author genie
 */
@Controller
@RequestMapping(value = "/accounts")
public class AccountController {

    private static final Logger LOG = LoggerFactory.getLogger(AccountController.class);

    @Autowired
    private AccountService accountService;

    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, consumes = "application/json")
    public ResultView register(HttpServletRequest req, HttpServletResponse res, @Valid @RequestBody Account account, BindingResult bindingResult) throws JsonProcessingException {
        //validation 실패
        if (bindingResult.hasErrors()) {
            return new ResultView("500", "Register fail : " + bindingResult.getFieldError().getDefaultMessage(), null);
        }
        //duplicated key exception
        Account result = accountService.createAccount(account);
        if (result == null) {
            return new ResultView("500", "Duplicated email or name", null);
        }

        return new ResultView("200", "Register success", account);
    }
}

@@ -32,16 +32,61 @@
 oller;%0A%0A
+import com.danchu.momuck.domain.LoginResult;%0A
 import c
@@ -430,24 +430,69 @@
 Controller;%0A
+import org.springframework.util.StringUtils;%0A
 import org.s
@@ -1945,10 +1945,511 @@
 ;%0A    %7D%0A
+%0A    @ResponseBody%0A    @RequestMapping(value = %22/login%22, method = RequestMethod.POST, consumes = %22application/json%22)%0A    public ResultView login(@RequestBody Account account) %7B%0A%0A        LoginResult loginResult = accountService.login(account);%0A%0A        if (loginResult.getCode() == LoginResult.SUCCESS.getCode()) %7B%0A            /**%0A             * @TODO AccessToken %EB%B0%9C%EA%B8%89%0A             */%0A        %7D%0A        return new ResultView(String.valueOf(loginResult.getCode()), loginResult.getMessage(), null);%0A    %7D%0A%0A
 %7D%0A

Add accountController