package com.ifish.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.ifish.dto.JsonResult;
import com.ifish.enums.IfishShopPlaceEnum;
import com.ifish.enums.ResultEnum;
import com.ifish.exception.IfishException;
import com.ifish.service.IfishGoodsService;

/**
 * 商品信息Controller
 * @author Administrator
 *
 */
@RestController
public class IfishGoodsAction {
	
	@Autowired
	private IfishGoodsService ifishGoodsService;
	
	/**
	 * 根据位置获取商品信息
	 * @param goodsPlace
	 * @return
	 */
	@RequestMapping(value="/ifishGoods/type/{goodsType}",method=RequestMethod.GET)
	public JsonResult<?> getIfishGoodsByGoodsPlace(@PathVariable("goodsType") Integer goodsPlace){
		//校验类型
		IfishShopPlaceEnum shopPlaceEnum = IfishShopPlaceEnum.getAdTypeEnum(goodsPlace);
		if(shopPlaceEnum==null){
			throw new IfishException(ResultEnum.error401);
		}
		return ifishGoodsService.getIfishGoodsByGoodsPlace(shopPlaceEnum);
	}
	
	/**
	 * 增加商品点击数
	 * @param goodsId
	 * @return
	 */
	@RequestMapping(value="/ifishGoods/{goodsId}/additionClickNum",method=RequestMethod.POST)
	public JsonResult<?> addClickNum(@PathVariable("goodsId") Integer goodsId){
		return ifishGoodsService.addClickNum(goodsId);
	}
	
}
