package com.ruixuan.jinniu.controller;

import com.ruixuan.common.core.controller.BaseController;
import com.ruixuan.common.core.domain.AjaxResult;
import com.ruixuan.common.core.page.TableDataInfo;
import com.ruixuan.jinniu.entity.KuaishouAdvertiser;
import com.ruixuan.jinniu.service.IKuaishouAdvertiserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 广告主Controller
 *
 * @author ruoyi
 * @date 2023-03-14
 */
@Api(tags = "广告主Controller")
@RestController
@RequestMapping("/kuaishou/advertiser")
public class KuaishouAdvertiserController extends BaseController {
    @Autowired
    private IKuaishouAdvertiserService KuaishouAdvertiserService;

    /**
     * 查询广告主列表
     */
    @ApiOperation(value = "查询广告主列表")
    @GetMapping("/list")
    public TableDataInfo list(KuaishouAdvertiser kuaishouAdvertiser) {
        startPage();
        List<KuaishouAdvertiser> list = KuaishouAdvertiserService.selectKuaishouAdvertiserList(kuaishouAdvertiser);
        return getDataTable(list);
    }

    /**
     * 新增广告主
     */
    @ApiOperation(value = "新增广告主")
    @PostMapping(value = "/add")
    public AjaxResult add(@RequestBody KuaishouAdvertiser kuaishouAdvertiser) {
        return toAjax(KuaishouAdvertiserService.insertKuaishouAdvertiser(kuaishouAdvertiser));
    }

    /**
     * 修改广告主
     */
    @ApiOperation(value = "修改广告主")
    @PostMapping(value = "/edit")
    public AjaxResult edit(@RequestBody KuaishouAdvertiser kuaishouAdvertiser) {
        return toAjax(KuaishouAdvertiserService.updateKuaishouAdvertiser(kuaishouAdvertiser));
    }

    /**
     * 获取广告主详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(KuaishouAdvertiserService.selectKuaishouAdvertiserById(id));
    }

    /**
     * 删除
     */
    @ApiOperation(value = "删除")
    @GetMapping(value = "/deleteById")
    public AjaxResult deleteById(@ApiParam("id") @RequestParam(value = "id", required = true) Long id) {
        return AjaxResult.success(KuaishouAdvertiserService.deleteKuaishouAdvertiserById(id));
    }
}

