package com.yida.data.school.secondClass.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yida.data.common.core.common.ResultBean;
import com.yida.data.common.core.entity.school.secondClass.EduSecondClassCourseLecturer;
import com.yida.data.common.core.utils.FebsUtil;
import com.yida.data.school.secondClass.service.EduSecondClassCourseLecturerService;
import com.yida.data.school.vo.secondClass.CourseLecturerVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * Controller
 *
 * @author zhanghaijun
 * @date 2022-04-11 11:09:15
 */
@Api(tags = "第二课堂-课程-讲师")
@Slf4j
@Validated
@RestController
@RequestMapping("/secondClass/course/lecturer")
@RequiredArgsConstructor
public class EduSecondClassCourseLecturerController {

    private final EduSecondClassCourseLecturerService eduSecondClassCourseLecturerService;

    @ApiOperation("分页查询讲师")
    @GetMapping("/listLecturerPage")
    public ResultBean<IPage<CourseLecturerVO>> listLecturerPage(@RequestParam(required = false) String name,
        @RequestParam(defaultValue = "1") Integer pageNum,
        @RequestParam(defaultValue = "10") Integer pageSize) {
        Long deptId = FebsUtil.getTopDeptId();
        return ResultBean.buildSuccess(eduSecondClassCourseLecturerService.listLecturerPage(pageNum, pageSize, name, deptId));
    }

    @ApiOperation("查询讲师列表")
    @GetMapping("/listLecturer")
    public ResultBean<List<CourseLecturerVO>> listLecturer() {
        return ResultBean.buildSuccess(eduSecondClassCourseLecturerService.listLecturer(FebsUtil.getTopDeptId()));
    }

    @ApiOperation("查询讲师详情")
    @GetMapping("/getInfo")
    public ResultBean<CourseLecturerVO> getInfo(Long id) {
        return ResultBean.buildSuccess(eduSecondClassCourseLecturerService.getInfo(id));
    }

    @ApiOperation("保存讲师信息")
    @PostMapping("/saveLecturer")
    public ResultBean saveLecturer(@RequestBody EduSecondClassCourseLecturer lecturer) {
        lecturer.setDeptId(FebsUtil.getTopDeptId());
        eduSecondClassCourseLecturerService.saveOrUpdate(lecturer);
        return ResultBean.buildSuccess();
    }

    @ApiOperation("删除讲师")
    @GetMapping("/delLecturer")
    public ResultBean delLecturer(Long id) {
        eduSecondClassCourseLecturerService.delLecturer(id);
        return ResultBean.buildSuccess();
    }
}
