package com.hc.gpweb.controller.back;

import com.hc.gpbusiness.model.WebBanner;
import com.hc.gpbusiness.service.WebBannerService;
import com.hc.gpcore.utils.result.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 广告表
 * (WebBanner)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:04
 */

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

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

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

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

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

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

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

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


}