package com.cab.controller;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.cab.service.ValidationCodeServiceImpl;
import com.cku.core.RESTResponse;
import com.cku.util.ServletUtils;

@Controller
@RequestMapping(value="utils")
public class ValidationCodeController {
	// private static final Logger logger = Logger.getLogger(ProvinceController.class);
	
	@Autowired
	public ValidationCodeServiceImpl validationService;
	
	@RequestMapping(value = "/apply-code")
	public void api_apply(HttpServletResponse response, HttpServletRequest request) throws IOException
	{
		RESTResponse result = new RESTResponse();
		try
		{
			String phone = ServletUtils.getParameter(request, "phone");
			
			String code = validationService.applyNewCode(phone);
			
			result = new RESTResponse("msg", code);
		}
		catch (Exception e)
		{
			result = new RESTResponse(e);
		}
		
		ServletUtils.writeResponse(response, result);
	}
}
