package com.ym.mec.student.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.dal.entity.ExtracurricularExercisesReply;
import com.ym.mec.biz.dal.page.ExtraExercilseQueryInfo;
import com.ym.mec.biz.service.ExtracurricularExercisesReplyService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.entity.HttpResponseResult;
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.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Joburgess
 * @Date 2020/3/26
 */
@Api(tags = "课外训练服务")
@RequestMapping("extracurricularExercisesReply")
@RestController
public class ExtracurricularExercisesReplyController extends BaseController {

    @Autowired
    private SysUserFeignService sysUserFeignService;
    @Autowired
    private ExtracurricularExercisesReplyService extracurricularExercisesReplyService;

    @ApiOperation(value = "获取学生的课外训练列表")
    @GetMapping("/findStudentExtraExercises")
    public HttpResponseResult findStudentExtraExercises(ExtraExercilseQueryInfo queryInfo){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if (sysUser == null) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        queryInfo.setStudentId(sysUser.getId());
        return succeed(extracurricularExercisesReplyService.findStudentExtraExercises(queryInfo));
    }

    @ApiOperation(value = "获取课外训练学生")
    @GetMapping("/findExtraExerciseStudents")
    public HttpResponseResult findExtraExerciseStudents(Long extraExerciseId,String studentName){
        return succeed(extracurricularExercisesReplyService.findExtraExerciseStudents(extraExerciseId,studentName));
    }

    @ApiOperation(value = "获取课外训练详情")
    @GetMapping("/findStudentExtraExerciseDetail")
    public HttpResponseResult findStudentExtraExerciseDetail(Long studentExerciseId){
        return succeed(extracurricularExercisesReplyService.findStudentExtraExerciseDetail(studentExerciseId));
    }

    @ApiOperation(value = "提交课外训练作业")
    @GetMapping("/submitExtraExercise")
    public HttpResponseResult submitExtraExercise(ExtracurricularExercisesReply extracurricularExercisesReply){
        extracurricularExercisesReplyService.submitExtraExercise(extracurricularExercisesReply);
        return succeed();
    }

}
