package com.ifish.action;

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.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ifish.dto.JsonResult;
import com.ifish.enums.AdTypeEnum;
import com.ifish.enums.ResultEnum;
import com.ifish.exception.IfishException;
import com.ifish.service.AdInfoService;

/**
 * 广告信息
 *
 * @author Administrator
 *
 */
@Controller
@RequestMapping(value = "/adInfos")
@ResponseBody
public class AdInfoAction {

    @Autowired
    private AdInfoService adInfoService;

    /**
     * 根据类型获取广告信息
     *
     * @param adType
     * @return
     */
    @RequestMapping(value = "/type/{adType}", method = RequestMethod.GET)
    public JsonResult<?> getAdInfosByType(@PathVariable("adType") int adType) {
        //校验类型
        AdTypeEnum adTypeEnum = AdTypeEnum.getAdTypeEnum(adType);
        if (adTypeEnum == null) {
            throw new IfishException(ResultEnum.error401);
        }
        return adInfoService.getAdInfosByType(adTypeEnum);
    }

    /**
     * 获取广告信息表最大ID
     *
     * @return
     */
    @RequestMapping(value = "getMaxInfo", method = RequestMethod.GET)
    public JsonResult<?> getMaxInfo() {
        return adInfoService.getMaxInfo();
    }
}
