package cn.iocoder.yudao.module.base.controller.app;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils;
import cn.iocoder.yudao.framework.tenant.core.aop.TenantIgnore;
import cn.iocoder.yudao.module.base.entity.SchoolFeedBack;
import cn.iocoder.yudao.module.base.service.SchoolFeedbackService;
import cn.iocoder.yudao.module.base.vo.SchoolFeedBackVO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 评价
 * @Author: 86187
 * @Date: 2025/04/03 14:25
 * @Version: 1.0
 */
@Tag(name = "小程序 - 评价")
@RestController
@RequestMapping("/feed-back")
@Validated
@RequiredArgsConstructor
public class AppSchoolFeedBackController {

    private final SchoolFeedbackService schoolFeedbackService;

    /**
     * 评价
     *
     * @param request 请求
     * @return
     */
    @TenantIgnore
    @PostMapping
    public CommonResult<?> add(@RequestBody @Validated SchoolFeedBackVO request) {
        // 判断租户id是否为空
        if (request.getTenantId() == null) {
            throw new RuntimeException("租户id不能为空");
        }
        request.setUserId(SecurityFrameworkUtils.getLoginUserId());
        schoolFeedbackService.add(request);
        return CommonResult.success(true);
    }

    /**
     * 分页查询评价
     *
     * @param request  请求
     * @param pageNo   页码
     * @param pageSize 每页大小
     * @return CommonResult<?>
     */
    @GetMapping("/page")
    @TenantIgnore
    public CommonResult<?> page(SchoolFeedBackVO request,
                                @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) {
        Page<SchoolFeedBack> page = new Page<>(pageNo, pageSize);
        return CommonResult.success(schoolFeedbackService.queryPage(page, request));
    }
}
