package com.yonge.cooleshow.bbs.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.bbs.dto.search.BbsAuthRecordSearch;
import com.yonge.cooleshow.bbs.entity.BbsAuthRecord;
import com.yonge.cooleshow.bbs.service.BbsAuthRecordService;
import com.yonge.cooleshow.bbs.valid.UpdateGroup;
import com.yonge.cooleshow.bbs.vo.BbsAuthRecordVo;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import com.yonge.toolset.base.page.PageInfo;
import com.yonge.toolset.mybatis.support.PageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/bbsAuthRecord")
@Api(value = "文章审核", tags = "文章审核")
public class BbsAuthRecordController extends BaseController {
    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private BbsAuthRecordService bbsAuthRecordService;

    @PostMapping("/page")
    @ApiOperation(value = "后台管理-审核-查询文章审核列表")
    public HttpResponseResult<PageInfo<BbsAuthRecordVo>> page(@RequestBody BbsAuthRecordSearch query) {
        IPage<BbsAuthRecordVo> pages = bbsAuthRecordService.selectPage(PageUtil.getPage(query), query);
        return succeed(PageUtil.pageInfo(pages));
    }

    @PostMapping("/update")
    @ApiOperation(value = "后台管理-审核-修改文章审核状态")
    public HttpResponseResult<PageInfo<BbsAuthRecordVo>> updateAuditState(@Validated(UpdateGroup.class) @RequestBody BbsAuthRecord record) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        record.setVerifyUserId(user.getId());
        bbsAuthRecordService.updateAuditState(record);
        return succeed();
    }
}