package com.yiqi.api.controller.common;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yiqi.common.constant.UrlConstants;
import com.yiqi.common.core.domain.AuthHolder;
import com.yiqi.common.core.domain.R;
import com.yiqi.common.enums.DeleteStatus;
import com.yiqi.common.enums.OrderSourceType;
import com.yiqi.common.enums.SourceType;
import com.yiqi.common.enums.SysBoolType;
import com.yiqi.core.domain.GoodsComment;
import com.yiqi.core.domain.dto.weapp.WeAppGoodsCommentAddDTO;
import com.yiqi.core.domain.dto.weapp.WeAppGoodsCommentQueryDTO;
import com.yiqi.core.domain.dto.weapp.WeAppGoodsInfoQueryDTO;
import com.yiqi.core.domain.vo.weapp.WeAppGoodsCommentQueryVO;
import com.yiqi.core.domain.vo.weapp.WeAppGoodsInfoQueryVO;
import com.yiqi.core.service.IGoodsCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author zjw
 * @date 2023/12/19
 */
@Api(tags = "商品评论")
@RestController
@RequestMapping(value = UrlConstants.wxappApi + "/goods/comment")
public class WeAppGoodsCommentController {
    @Autowired
    private IGoodsCommentService goodsCommentService;

    @ApiOperation("分页获取商品评论列表")
    @PostMapping(value = "findPage")
    public R<WeAppGoodsCommentQueryVO> findPage(@RequestBody @Valid WeAppGoodsCommentQueryDTO weAppGoodsCommentQueryDTO) {
        return R.ok(goodsCommentService.findPage(weAppGoodsCommentQueryDTO));
    }

    @Transactional(rollbackFor = Exception.class)
    @ApiOperation("app新增商品评论")
    @PostMapping(value = "/addGoodsCommentByApp")
    public R<Integer> addGoodsCommentByApp(@RequestBody @Valid WeAppGoodsCommentAddDTO weAppGoodsCommentAddDTO) {
        GoodsComment goodsComment = new GoodsComment();
        BeanUtils.copyProperties(weAppGoodsCommentAddDTO, goodsComment);
        goodsComment.setCommentSrcType(OrderSourceType.APP.getCode());
        goodsComment.setDelFlag(DeleteStatus.OK.getCode());
        goodsComment.setUserId(AuthHolder.userId());
        goodsComment.setIsShow(SysBoolType.YES.getCode());
        goodsComment.setIsVirtual(SysBoolType.NO.getCode());
        goodsComment.buildCreateData();
        return R.ok(goodsCommentService.insertGoodsComment(goodsComment, null, null));
    }


}




















