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

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

import javax.validation.Valid;


/**
 * (Msgs)表控制层
 *
 * @author makejava
 * @since 2024-02-29 18:52:03
 */

@RestController
@RequestMapping("/new/api/back/msgs")
public class BackMsgsController {

    /**
     * 服务对象
     */
    private final MsgsService msgsService;

    public BackMsgsController(MsgsService msgsService) {
        this.msgsService = msgsService;
    }

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

    @PostMapping("/insert")
    @ApiOperation(value = "新增 Msgs", response = Result.class)
    public Result addMsgs(@Valid @RequestBody Msgs msgs) {

        return Result.success(msgsService.insert(msgs));
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改 Msgs", response = Result.class)
    public Result updateMsgs(@RequestBody Msgs msgs) {
        return Result.success(msgsService.update(msgs));
    }

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

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


}
