package com.yonge.cooleshow.teacher.controller;

import com.yonge.cooleshow.biz.dal.entity.TeacherFreeTime;
import com.yonge.cooleshow.biz.dal.service.SysUserService;
import com.yonge.cooleshow.biz.dal.service.TeacherFreeTimeService;
import com.yonge.cooleshow.common.controller.BaseController;
import com.yonge.cooleshow.common.entity.HttpResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 老师可排课时间表(TeacherFreeTime)表控制层
 *
 * @author zx
 * @since 2022-03-25 10:04:26
 */
@Api(tags = "老师可排课时间表")
@RestController
@RequestMapping("${app-config.url.teacher:}/teacherFreeTime")
public class TeacherFreeTimeController extends BaseController {
    @Resource
    private TeacherFreeTimeService teacherFreeTimeService;
    @Resource
    private SysUserService sysUserService;

    @ApiOperation(value = "新增、修改老师排课时间")
    @PostMapping("/upSet")
    public HttpResponseResult upSet(@Valid @RequestBody TeacherFreeTime teacherFreeTime){
        teacherFreeTime.setTeacherId(sysUserService.getUserId());
        teacherFreeTimeService.upSet(teacherFreeTime);
        return succeed();
    }

    @ApiOperation(value = "获取老师排课时间")
    @GetMapping("/get")
    public HttpResponseResult<TeacherFreeTime> get(){
        TeacherFreeTime freeTime = teacherFreeTimeService.lambdaQuery().eq(TeacherFreeTime::getTeacherId, sysUserService.getUserId()).one();
        return succeed(freeTime);
    }
}

