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

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

import javax.validation.Valid;


/**
 * (ClassConfigSponsor)表控制层
 *
 * @author java
 * @since 2021-05-28 14:11:29
 */

@RestController
@RequestMapping("/new/api/back/classConfigSponsor")
public class BackClassConfigSponsorController {

    /**
     * 服务对象
     */
    private final ClassConfigSponsorService classConfigSponsorService;

    public BackClassConfigSponsorController(ClassConfigSponsorService classConfigSponsorService) {
        this.classConfigSponsorService = classConfigSponsorService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 ClassConfigSponsor", response = Result.class)
    public Result addClassConfigSponsor(@Valid @RequestBody ClassConfigSponsor classConfigSponsor) {
        return Result.success(classConfigSponsorService.insert(classConfigSponsor));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 ClassConfigSponsor", response = Result.class)
    public Result updateClassConfigSponsor(@RequestBody ClassConfigSponsor classConfigSponsor) {
        return Result.success(classConfigSponsorService.update(classConfigSponsor));
    }

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

    @GetMapping("/list")
    @ApiOperation(value = "获取 ClassConfigSponsor列表(分页)", response = Result.class)
    public Result listClassConfigSponsor(@RequestParam(defaultValue = "0") Integer page,
                                         @RequestParam(defaultValue = "0") Integer size,
                                         @RequestParam(required = false) Integer classId) {
        return Result.success(classConfigSponsorService.queryAllByLimit(page, size, classId));
    }


}
