package com.xhkjedu.slive.controller.liveplay;

import com.xhkjedu.slive.model.liveplay.LCourseType;
import com.xhkjedu.slive.service.liveplay.CourseTypeService;
import com.xhkjedu.utils.N_Utils;
import com.xhkjedu.vo.ResultVo;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
* @author ywx
* @classname LCourseTypeController
* @description
* @date 2021/01/23 11:41
**/
@RestController
@RequestMapping("/course_type")
public class CourseTypeController {
    @Resource
    private CourseTypeService courseTypeService;

    @PostMapping("/add")
    public ResultVo add(@RequestBody LCourseType type) {
        courseTypeService.save(type);
        return new ResultVo(0, "保存成功");
    }

    @PostMapping("/delete")
    public ResultVo delete(@RequestBody LCourseType type) {
        N_Utils.validation(new Object[]{type.getCtypeid(),"课程分类id",1});
        courseTypeService.deleteById(type.getCtypeid());
        return new ResultVo(0,"删除成功");
    }

    @PostMapping("/update")
    public ResultVo update(@RequestBody LCourseType type) {
        N_Utils.validation(new Object[]{type.getCtypeid(),"课程分类id",1});
        courseTypeService.update(type);
        return new ResultVo(0,"修改成功");
    }

    @PostMapping("/list")
    public ResultVo list(@RequestBody LCourseType type) {
        Integer schoolid = type.getSchoolid();
        N_Utils.validation(new Object[]{schoolid,"学校id",1});
        Integer ctstate = type.getCtstate();
        if (ctstate == null) ctstate = 1;
        List<LCourseType> list = courseTypeService.listAll(schoolid, ctstate);
        return new ResultVo(0,"获取课程分类列表成功",list);
    }
}
