package com.project.template.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.project.template.model.User;
import com.project.template.services.UserServices;
import com.project.template.util.APPConst;
import com.project.template.xml.Response;
import com.project.template.xml.Result;

@Controller
public class UserController {
	@Autowired
	private UserServices userServices;

	private static Logger log = LoggerFactory.getLogger(UserController.class);

	@RequestMapping(value = "/getUser.api", params = { "userName" }, method = RequestMethod.GET, produces = { MediaType.APPLICATION_JSON_VALUE,
			MediaType.APPLICATION_XML_VALUE })
	public @ResponseBody Result login(@RequestParam(value = "userName") String userName) throws Exception {
		Result andaraLink = new Result();
		Response response = new Response();

		User user = userServices.findByUserName(userName.trim());

		if (user == null) {
			response.setCode(APPConst.RESPONSE_ERROR);
			response.setDescription("user is not registered");
			andaraLink.setResponse(response);
			return andaraLink;
		}

		response.setCode(APPConst.RESPONSE_SUCCESS);
		response.setDescription("user: " + user.getUserName() + " is registered");

		andaraLink.setResponse(response);
		return andaraLink;
	}

	@ExceptionHandler(Exception.class)
	public @ResponseBody Result errorHandle(Exception e) {
		Result andaraLink = new Result();

		Response response = new Response();
		response.setCode(APPConst.RESPONSE_ERROR);
		response.setDescription(e.getMessage());

		andaraLink.setResponse(response);

		log.error(e.getMessage(), e);
		return andaraLink;
	}
}

@@ -1235,34 +1235,30 @@
  %7B%0A%09%09Result 
-andaraLink
+result
  = new Resul
@@ -1487,26 +1487,22 @@
 d%22);%0A%09%09%09
-andaraLink
+result
 .setResp
@@ -1527,26 +1527,22 @@
 %09return 
-andaraLink
+result
 ;%0A%09%09%7D%0A%0A%09
@@ -1663,34 +1663,30 @@
 tered%22);%0A%0A%09%09
-andaraLink
+result
 .setResponse
@@ -1702,34 +1702,30 @@
 );%0A%09%09return 
-andaraLink
+result
 ;%0A%09%7D%0A%0A%09@Exce
@@ -1819,26 +1819,22 @@
 %09Result 
-andaraLink
+result
  = new R
@@ -1972,26 +1972,22 @@
 ());%0A%0A%09%09
-andaraLink
+result
 .setResp
@@ -2048,18 +2048,14 @@
 urn 
-andaraLink
+result
 ;%0A%09%7D

update reference