package com.yonge.cooleshow.website.controller;

import com.yonge.cooleshow.auth.api.client.SysUserFeignService;
import com.yonge.cooleshow.auth.api.entity.SysUser;
import com.yonge.cooleshow.biz.dal.dto.PracticeTimesSetting;
import com.yonge.cooleshow.biz.dal.entity.TeacherFreeTime;
import com.yonge.cooleshow.biz.dal.service.TeacherFreeTimeService;
import com.yonge.cooleshow.biz.dal.vo.TeacherFreeTimeVo;
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.http.HttpStatus;
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 javax.validation.Valid;

/**
 * 老师可排课时间表(TeacherFreeTime)表控制层
 *
 * @author zx
 * @since 2022-03-25 10:04:26
 */
@Api(tags = "老师可排课时间表")
@RestController
@RequestMapping("/teacherFreeTime")
public class TeacherFreeTimeController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TeacherFreeTimeService teacherFreeTimeService;
    @Resource
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "新增、修改老师陪练课设置")
    @PostMapping("/upSet")
    public HttpResponseResult upSet(@Valid @RequestBody TeacherFreeTime teacherFreeTime){
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        teacherFreeTime.setTeacherId(user.getId());
        teacherFreeTimeService.upSet(teacherFreeTime);
        return succeed();
    }

    @ApiOperation(value = "获取老师陪练课设置")
    @PostMapping("/getDetail")
    public HttpResponseResult<TeacherFreeTimeVo> getDetail(@RequestBody PracticeTimesSetting practiceTimesSetting){
        SysUser user = sysUserFeignService.queryUserInfo();
        if (user == null || null == user.getId()) {
            return failed(HttpStatus.FORBIDDEN, "请登录");
        }
        practiceTimesSetting.setUserId(user.getId());
        return succeed(teacherFreeTimeService.getDetail(practiceTimesSetting));
    }
}

