package com.cool.bang.modules.approval.controller;

import com.cool.bang.common.base.BaseController;
import com.cool.bang.common.constant.ControllerConstant;
import com.cool.bang.common.web.request.PageDomain;
import com.cool.bang.common.web.response.Result;
import com.cool.bang.common.web.response.module.ResultTable;
import com.cool.bang.modules.approval.domain.ApprovalRecord;
import com.cool.bang.modules.approval.service.IApprovalRecordService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 审批记录
 *
 * @author PeiZhi Guo
 * @version 1.0.0
 * 2022-08-29 16:46
 */
@RestController
@RequestMapping(ControllerConstant.APPROVAL + "record/v1")
public class ApprovalRecordController extends BaseController {

    private IApprovalRecordService approvalRecordService;

    @Autowired
    public ApprovalRecordController(IApprovalRecordService approvalRecordService) {
        this.approvalRecordService = approvalRecordService;
    }

    @GetMapping
    public ResultTable main(PageDomain pageDomain, ApprovalRecord param) {
        PageInfo<ApprovalRecord> approvalRecordPage = approvalRecordService.page(pageDomain, param);
        return pageTable(approvalRecordPage.getList(), approvalRecordPage.getTotal());
    }

    @GetMapping("list")
    public Result list(ApprovalRecord param) {
        List<ApprovalRecord> approvalRecordPage = approvalRecordService.list(param);
        return success(approvalRecordPage);
    }

    @GetMapping("{id}")
    public Result get(@PathVariable Long id) {
        return success(approvalRecordService.queryById(id));
    }

    @PostMapping
    public Result add(ApprovalRecord approvalRecord) {
        return decide(approvalRecordService.save(approvalRecord));
    }

    @PostMapping("edit")
    public Result edit(ApprovalRecord approvalRecord) {
        return decide(approvalRecordService.update(approvalRecord));
    }

    @DeleteMapping("{id}")
    public Result remove(@PathVariable Integer id) {
        return decide(approvalRecordService.removeById(id));
    }

}
