package com.xhkjedu.sclass.controller.classroom;

import com.xhkjedu.annotation.Action;
import com.xhkjedu.sclass.model.classroom.TClassroomVideo;
import com.xhkjedu.sclass.service.classroom.ClassroomVideoService;
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;
import java.util.Map;

/**
 * @author ywx
 * @classname ClassroomVideoController
 * @description 课堂视频管理
 * @date 2023/2/3 10:04
 **/
@RestController
@RequestMapping("roomv")
public class ClassroomVideoController {
    @Resource
    private ClassroomVideoService classroomVideoService;

    @PostMapping("/list")
    public ResultVo list(@RequestBody TClassroomVideo video) {
        Long roomid = video.getRoomid();
        N_Utils.validation(new Object[]{roomid, "课堂id", 1});
        List<Map> list = classroomVideoService.listByRoomId(roomid);
        return new ResultVo(0, "获取列表成功", list);
    }

    @PostMapping("/add")
    @Action("课堂视频-增加")
    public ResultVo add(@RequestBody TClassroomVideo video) {
        N_Utils.validation(new Object[]{video.getRoomid(), "课堂id", 1});
        classroomVideoService.save(video);
        return new ResultVo(0, "保存成功");
    }

    @PostMapping("/delete")
    @Action("课堂视频-删除")
    public ResultVo delete(@RequestBody TClassroomVideo video) {
        Integer rvid = video.getRvid();
        N_Utils.validation(new Object[]{rvid, "课堂视频id", 1});
        classroomVideoService.deleteById(rvid);
        return new ResultVo(0, "删除成功");
    }

    @PostMapping("/update")
    @Action("课堂视频-修改")
    public ResultVo update(@RequestBody TClassroomVideo video) {
        N_Utils.validation(new Object[]{video.getRvid(), "课堂视频id", 1});
        classroomVideoService.update(video);
        return new ResultVo(0, "修改成功");
    }
}
