package com.ym.mec.web.controller.student;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.io.IOException;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

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;

/**
 * @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 = "重新提交")
    @PutMapping(value = "/update",produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Object update(@RequestBody StudentCourseHomework studentCourseHomework){
        studentCourseHomework.setStatus(YesOrNoEnum.YES);
        studentCourseHomeworkService.update(studentCourseHomework);
        return succeed();
    }

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

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

}
