package com.danchu.momuck.controller;

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.PathVariable;
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 com.danchu.momuck.service.RestaurantService;
import com.danchu.momuck.view.ResultView;
import com.danchu.momuck.vo.Account;
import com.danchu.momuck.vo.Restaurant;

@Controller
@RequestMapping(value = "/restaurants")
public class RestaurantController {

	@Autowired
	RestaurantService restaurantService;

	@ResponseBody
	@RequestMapping(method = RequestMethod.POST, consumes = "application/json")
	public ResultView register(HttpServletRequest req, HttpServletResponse res, @RequestBody Restaurant restaurant) {

		Restaurant result = restaurantService.createRestaurant(restaurant);
		if (result == null) {
			return new ResultView("500", "Duplicated email or name", null);
		}
		return new ResultView("200", "Register success", restaurant);
	}
	
	@ResponseBody
	@RequestMapping(method = RequestMethod.DELETE, consumes = "application/json")
	public ResultView delete(HttpServletRequest req, HttpServletResponse res, @PathVariable String restaurantName) {
		restaurantService.deleteRestaurant(restaurantName);
		return new ResultView("200", "SUCCESS", null);
	}
}

@@ -124,16 +124,47 @@
 esponse;
+%0Aimport javax.validation.Valid;
 %0A%0Aimport
@@ -270,16 +270,69 @@
 roller;%0A
+import org.springframework.validation.BindingResult;%0A
 import o
@@ -729,45 +729,8 @@
 ew;%0A
-import com.danchu.momuck.vo.Account;%0A
 impo
@@ -766,16 +766,69 @@
 urant;%0A%0A
+/**%0A * RestaurantController %0A *%0A * @author lhbv1%0A */%0A
 @Control
@@ -1127,16 +1127,23 @@
 nse res,
+ @Valid
  @Reques
@@ -1169,20 +1169,215 @@
 staurant
-) %7B%0A
+, BindingResult bindingResult) %7B%0A%09%09//validation %EC%8B%A4%ED%8C%A8%0A%09%09if(bindingResult.hasErrors()) %7B%0A%09%09%09return new ResultView(%22500%22, %22Register fail%22 + bindingResult.getFieldError().getDefaultMessage(), null);%0A%09%09%7D%0A%09%09
 %0A%09%09Resta
@@ -1500,32 +1500,23 @@
 %22, %22
-Duplicated email or name
+Register failed
 %22, n
@@ -1601,32 +1601,537 @@
 %0A%09@ResponseBody%0A
+%09@RequestMapping(value = %22/%7Brestaurant_id%7D%22, method = RequestMethod.GET, consumes = %22application/json%22)%0A%09public ResultView select(HttpServletRequest req, HttpServletResponse res, @PathVariable(%22restaurant_id%22) int restaurantId) %7B%0A%09%09Restaurant result = restaurantService.selectRestaurant(restaurantId);%0A%09%09if(result == null) %7B%0A%09%09%09return new ResultView(%22500%22, %22No data%22, null);%0A%09%09%7D%0A%09%09return new ResultView(%22200%22, %22Success%22, result);%0A%09%7D%0A%09%0A%09/**%0A%09 * %0A%09 * @TODO %EB%A7%A4%EC%9E%A5 %EC%A3%BC%EC%9D%B8%EC%9D%B4%EB%9E%91 %EA%B4%80%EB%A6%AC%EC%9E%90%EB%A7%8C %EC%A7%80%EC%9A%B8%EC%88%98 %EC%9E%88%EB%8F%84%EB%A1%9D %EB%A1%9C%EC%A7%81 %EC%B6%94%EA%B0%80%ED%95%B4%EC%95%BC%EB%90%A8%0A%09 */%0A%09@ResponseBody%0A
 %09@RequestMapping
@@ -2306,19 +2306,33 @@
 tName) %7B
+ 
 %0A%09%09
+int result = 
 restaura
@@ -2375,16 +2375,95 @@
 tName);%0A
+%09%09if(result %3C 0) %7B%0A%09%09%09return new ResultView(%22500%22, %22Delete failed%22, null);%0A%09%09%7D%0A
 %09%09return
@@ -2490,15 +2490,22 @@
 %22, %22
-SUCCESS
+Delete success
 %22, n

Add phone_number, avg_score validation