/**
 * <p>Project name is RoomieS<br>
 * Package name is life.theroomie.restController<br>
 * File name is Register.java<br>
 *
 * @author YeonGyu Yang
 * @since Apr 1, 2016
 */
package com.faveroomies.restController;

import org.apache.ibatis.annotations.Param;
import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.validation.ObjectError;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.faveroomies.form.RegisterForm;
import com.faveroomies.mapper.RoomieMapper;

/**
 * 
 * @author YeonGyu Yang
 * @Since Apr 1, 2016
 *
 */
@RestController
@MapperScan("life.theroomie.mapper")
public class RestRegister {

	private Logger logger = LoggerFactory.getLogger(RestRegister.class);

	@Autowired
	private RoomieMapper roomieMapper;

	@RequestMapping(value = "/register/overlap", params = "username")
	public boolean usernameOverlap(@Param("username") String username) {

		logger.info("Username Overlap Check");

		int overlapCount = roomieMapper.countUser(username);

		if (overlapCount > 0 || username.length() <= 4)
			return true;
		else
			return false;

	}

	@RequestMapping(value = "/register/overlap", params = "email")
	public boolean emailOverlap(@Validated RegisterForm registerForm, BindingResult bindingResult, ModelMap modelMap) {

		logger.info("Eamil Overlap Check");

		int overlapCount = 0;

		if (registerForm.getEmail().trim().split("[+]").length > 1 && registerForm.getEmail().trim().length() > 0) {
			logger.info(registerForm.getEmail().trim().split("[+]")[0]);
			overlapCount = roomieMapper.countEmail(registerForm.getEmail().trim().split("[+]")[0] + "%");
			logger.info(((Integer) overlapCount).toString());
		} else if (registerForm.getEmail().trim().length() > 0) {
			overlapCount = roomieMapper.countEmail(registerForm.getEmail().trim() + "%");
			logger.info(((Integer) overlapCount).toString());
		}

		if (overlapCount > 0 || registerForm.getEmail().trim().split("[@]").length <= 1)
			return true;
		else
			return false;

	}

	@RequestMapping(value = "/register/validate", method = RequestMethod.POST)
	public boolean regProcess(@Validated RegisterForm registerForm, BindingResult bindingResult) {

		logger.info("Register Validated");

		if (bindingResult.hasErrors()) {
			return false;
		} else
			return true;

	}

}

@@ -496,268 +496,42 @@
 ork.
-validation.BindingResult;%0Aimport org.springframework.validation.ObjectError;%0Aimport org.springframework.validation.annotation.Validated;%0Aimport org.springframework.web.bind.annotation.RequestMapping;%0Aimport org.springframework.web.bind.annotation.RequestMethod
+web.bind.annotation.RequestMapping
 ;%0Aim
@@ -596,50 +596,8 @@
 r;%0A%0A
-import com.faveroomies.form.RegisterForm;%0A
 impo
@@ -1329,72 +1329,35 @@
 ap(@
-Validated RegisterForm registerForm, BindingResult bindingResult
+Param(%22email%22) String email
 , Mo
@@ -1446,39 +1446,21 @@
 %0A%0A%09%09if (
-registerForm.getE
+e
 mail
-()
 .trim().
@@ -1486,39 +1486,21 @@
  %3E 1 && 
-registerForm.getE
+e
 mail
-()
 .trim().
@@ -1530,39 +1530,21 @@
 er.info(
-registerForm.getE
+e
 mail
-()
 .trim().
@@ -1603,39 +1603,21 @@
 ntEmail(
-registerForm.getE
+e
 mail
-()
 .trim().
@@ -1706,39 +1706,21 @@
 lse if (
-registerForm.getE
+e
 mail
-()
 .trim().
@@ -1777,39 +1777,21 @@
 ntEmail(
-registerForm.getE
+e
 mail
-()
 .trim() 
@@ -1886,31 +1886,13 @@
  %7C%7C 
-registerForm.getE
+e
 mail
-()
 .tri
@@ -1970,299 +1970,6 @@
 %09%7D%0A%0A
-%09@RequestMapping(value = %22/register/validate%22, method = RequestMethod.POST)%0A%09public boolean regProcess(@Validated RegisterForm registerForm, BindingResult bindingResult) %7B%0A%0A%09%09logger.info(%22Register Validated%22);%0A%0A%09%09if (bindingResult.hasErrors()) %7B%0A%09%09%09return false;%0A%09%09%7D else%0A%09%09%09return true;%0A%0A%09%7D%0A%0A
 %7D%0A

Update Rest Controller