package com.yami.shop.multishop.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.AdvertInfo;
import com.yami.shop.bean.param.AdvertInfoParam;
import com.yami.shop.service.IAdvertInfoService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


/**
 * @author wy
 */
@RestController
@RequestMapping("/advert")
public class AdvertInfoController {

    @Resource
    private IAdvertInfoService advertInfoService;

    @ApiOperation("添加编辑广告")
    @PostMapping("/addOrUpdate")
    public ResponseEntity<Void> addOrUpdate(@RequestBody AdvertInfoParam param) {
        return advertInfoService.addOrUpdate(param);
    }

    @ApiOperation("查看")
    @GetMapping("/get/{id}")
    public ResponseEntity<AdvertInfoParam> get(@PathVariable("id") Integer id) {
        return advertInfoService.get(id);
    }

    @ApiOperation("搜索")
    @GetMapping("/search")
    public ResponseEntity<IPage<AdvertInfo>> search(@RequestParam(value = "advertName", required = false) String advertName,
                                                    @RequestParam(value = "status",required = false) Integer status,
                                                    @RequestParam(value = "current", required = false, defaultValue = "1") Integer current,
                                                    @RequestParam(value = "size",required = false, defaultValue = "10") Integer size) {
        return advertInfoService.search(advertName, status, current, size);
    }

    @ApiOperation("删除")
    @GetMapping("/del/{id}")
    public ResponseEntity<Void> del(@PathVariable("id") Integer id) {
        return advertInfoService.del(id);
    }

    @ApiOperation("上下线")
    @GetMapping("/operate/{id}")
    public ResponseEntity<Void> operate(@PathVariable("id") Integer id) {
        return advertInfoService.operate(id);
    }

}
