package com.hc.web.controller.browser.back;

import com.hc.business.model.Banner;
import com.hc.business.service.BannerService;
import com.hc.core.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 广告表
 * (Banner)表控制层
 *
 * @author java
 * @since 2020-11-26 09:29:54
 */

@RestController
@RequestMapping("/new/api/back/banner")
public class BackBannerController {

    /**
     * 服务对象
     */
    private final BannerService bannerService;

    public BackBannerController(BannerService bannerService) {
        this.bannerService = bannerService;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "依据主键获取 Banner", response = Result.class)
    public Result selectBackDetail(@PathVariable("id") Integer id) {
        return Result.success(this.bannerService.queryById(id));
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增 Banner", response = Result.class)
    public Result addBackBanner(@Valid @RequestBody Banner banner) {
        return Result.success(bannerService.insert(banner));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 Banner", response = Result.class)
    public Result updateBackBanner(@RequestBody Banner banner) {
        return Result.success(bannerService.update(banner));
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "依据主键删除 Banner", response = Result.class)
    public Result deleteBackBanner(@PathVariable("id") Integer id) {
        return Result.success(bannerService.deleteById(id));
    }

    @GetMapping("/list")
    @ApiOperation(value = "获取 Banner列表(分页)", response = Result.class)
    public Result listBackBanner(@RequestParam(defaultValue = "0") Integer page,
                                 @RequestParam(defaultValue = "0") Integer size) {
        return Result.success(bannerService.queryAllByLimit(page, size));
    }


}