package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.StudentCourseHomeworkReply;
import com.ym.mec.biz.dal.page.StudentCourseHomeworkReplyQueryInfo;
import com.ym.mec.biz.service.StudentCourseHomeworkReplyService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2019/9/19
 */
@RequestMapping("teacherCourseHomeworkReply")
@Api(tags = "作业评论-教师端")
@RestController
public class TeacherCourseHomeworkReplyController extends BaseController {

    @Autowired
    private StudentCourseHomeworkReplyService studentCourseHomeworkReplyService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增回复")
    @PostMapping("/add")
    public Object add(@RequestBody StudentCourseHomeworkReply studentCourseHomeworkReply) {
        SysUser user = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(user)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        studentCourseHomeworkReply.setUserId(user.getId());
        studentCourseHomeworkReplyService.insertTeacherReply(studentCourseHomeworkReply);
        return succeed();
    }

    @ApiOperation(value = "回复查询")
    @GetMapping("/queryPage")
    public Object queryPage(StudentCourseHomeworkReplyQueryInfo queryInfo){
        return succeed(studentCourseHomeworkReplyService.queryPage(queryInfo));
    }

    @ApiOperation(value = "删除回复")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "回复ID", required = true) @PathVariable("id") Long id){
        studentCourseHomeworkReplyService.delete(id);
        return succeed();
    }

}
