package com.hc.gpweb.controller.back;


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

import javax.validation.Valid;


/**
 * 板块表(Module)表控制层
 *
 * @author java
 * @since 2020-07-29 16:23:10
 */

@RestController
@RequestMapping("/api/back/module")
public class BackModulesController {

    /**
     * 服务对象
     */
    private final WebModulesService moduleService;

    public BackModulesController(WebModulesService moduleService) {
        this.moduleService = moduleService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 Module", response = Result.class)
    public Result addBackModules(@Valid @RequestBody WebModules modules) {
        return Result.success(moduleService.insert(modules));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 Module", response = Result.class)
    public Result updateBackModules(@RequestBody WebModules modules) {
        return Result.success(moduleService.update(modules));
    }

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

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


}