package com.yonge.cooleshow.teacher.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yonge.cooleshow.biz.dal.dto.search.MyCourseSearch;
import com.yonge.cooleshow.biz.dal.entity.CourseScheduleReplied;
import com.yonge.cooleshow.biz.dal.service.CourseRepliedService;
import com.yonge.cooleshow.biz.dal.service.SysUserService;
import com.yonge.cooleshow.biz.dal.vo.CourseRepliedVo;
import com.yonge.cooleshow.biz.dal.vo.MyRepliedVo;
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.validation.annotation.Validated;
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.annotation.Resource;

/**
 * @Author: cy
 * @Date: 2022/4/12
 */
@Api(tags = "趣纠课")
@RestController
@RequestMapping("${app-config.url.teacher:}/courseReplied")
public class CourseRepliedController extends BaseController {
    @Resource
    private SysUserService sysUserService;
    @Resource
    private CourseRepliedService repliedService;

    @ApiOperation(value = "首页-我的课程-课程详情-评价趣纠课", httpMethod = "POST", consumes = "application/json", produces = "application/json")
    @PostMapping(value = "/replied", consumes = "application/json", produces = "application/json")
    public HttpResponseResult<Object> replied(@Validated @RequestBody CourseScheduleReplied replied) {
        repliedService.replied(replied,sysUserService.getUser());
        return succeed();
    }

    @ApiOperation(value = "首页-我的课程-课程详情-查询趣纠课评价")
    @PostMapping(value = "/selectReplied")
    public HttpResponseResult<CourseRepliedVo> selectReplied(@Validated @RequestBody CourseScheduleReplied replied) {
        return succeed(repliedService.selectReplied(replied));
    }

    @ApiOperation(value = "首页-我收到的评价")
    @PostMapping(value = "/myReplied")
    public HttpResponseResult<PageInfo<MyRepliedVo>> myReplied(@RequestBody MyCourseSearch search) {
        search.setTeacherId(sysUserService.getUserId());
        search.setCourseType(null);
        IPage<MyRepliedVo> pages = repliedService.myReplied(PageUtil.getPage(search), search);
        return succeed(PageUtil.pageInfo(pages));
    }
}