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

import com.ym.mec.biz.dal.entity.CourseHomeworkTemplate;
import com.ym.mec.biz.dal.enums.YesOrNoEnum;
import com.ym.mec.biz.dal.page.CourseHomeWorkTemplateQueryInfo;
import com.ym.mec.biz.service.CourseHomeworkTemplateService;
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.web.bind.annotation.*;

import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2019/9/18
 */
@RequestMapping("courseHomeworkTemplate")
@Api(tags = "作业模板")
@RestController
public class CourseHomeworkTemplateController extends BaseController {


    @Autowired
    private CourseHomeworkTemplateService courseHomeworkTemplateService;

    @ApiOperation(value = "新增作业模板")
    @PostMapping("/add")
    public Object add(CourseHomeworkTemplate courseHomeworkTemplate){
        courseHomeworkTemplate.setDelFlag(YesOrNoEnum.NO);
        courseHomeworkTemplateService.insert(courseHomeworkTemplate);
        return succeed();
    }

    @ApiOperation(value = "删除作业模板")
    @PostMapping("/del/{id}")
    public Object del(@ApiParam(value = "科目编号", required = true) @PathVariable("id") Integer id){
        courseHomeworkTemplateService.delete(id);
        return succeed();
    }

    @ApiOperation(value = "修改作业模板")
    @PostMapping("/update")
    public Object update(CourseHomeworkTemplate courseHomeworkTemplate){
        if(Objects.isNull(courseHomeworkTemplate.getId())){
            return failed("请指定作业模板");
        }
        courseHomeworkTemplateService.update(courseHomeworkTemplate);
        return succeed();
    }

    @ApiOperation(value = "分页查询作业模板列表")
    @PostMapping("/queryPage")
    public Object queryPage(@RequestBody CourseHomeWorkTemplateQueryInfo queryInfo){
        return succeed(courseHomeworkTemplateService.queryPage(queryInfo));
    }

}
