package com.ym.mec.student.controller;

import com.ym.mec.biz.dal.entity.StudentCourseHomework;
import com.ym.mec.biz.dal.enums.YesOrNoEnum;
import com.ym.mec.biz.dal.page.CourseHomeworkQueryInfo;
import com.ym.mec.biz.service.StudentCourseHomeworkService;
import com.ym.mec.common.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @Author Joburgess
 * @Date 2019/9/18
 */
@RequestMapping("studentCourseHomework")
@Api(tags = "学生作业")
@RestController
public class StudentCourseHomeworkController extends BaseController {

    @Autowired
    private StudentCourseHomeworkService studentCourseHomeworkService;

    @ApiOperation(value = "提交作业")
    @PostMapping(value = "/add",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object add(@RequestBody StudentCourseHomework studentCourseHomework){
        studentCourseHomework.setStatus(YesOrNoEnum.YES);
        studentCourseHomeworkService.insert(studentCourseHomework);
        return succeed();
    }

    @ApiOperation(value = "重新提交")
    @PostMapping(value = "/update",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object update(@RequestBody StudentCourseHomework studentCourseHomework){
        studentCourseHomework.setStatus(YesOrNoEnum.YES);
        studentCourseHomework.setId(studentCourseHomework.getCourseHomeworkId());
        studentCourseHomeworkService.update(studentCourseHomework);
        return succeed();
    }

    @ApiOperation(value = "获取学生作业界面详细信息")
    @GetMapping(value = "/findCourseHomeworkStudentDetail")
    public Object findCourseHomeworkStudentDetail(Long courseScheduleID) throws IOException {
        return succeed(studentCourseHomeworkService.findCourseHomeworkStudentDetail(courseScheduleID));
    }

    @ApiOperation(value = "分页查询作业列表")
    @PostMapping(value = "/queryPage")
    public Object queryPage(@RequestBody(required = false) CourseHomeworkQueryInfo queryInfo){
        if(queryInfo == null){
            queryInfo = new CourseHomeworkQueryInfo();
        }
        return succeed(studentCourseHomeworkService.queryPage(queryInfo));
    }

}
