package com.ym.mec.teacher.controller;

import com.ym.mec.auth.api.client.SysUserFeignService;
import com.ym.mec.auth.api.entity.SysUser;
import com.ym.mec.biz.service.SubjectService;
import com.ym.mec.common.controller.BaseController;
import com.ym.mec.common.filters.TenantIdThreadLocal;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Objects;

/**
 * @Author Joburgess
 * @Date 2019/9/26
 */
@RequestMapping("subject")
@Api(tags = "科目服务-教师端")
@RestController
public class TeacherSubjectController extends BaseController {

    @Autowired
    private SubjectService subjectService;
    @Autowired
    private SysUserFeignService sysUserFeignService;

    @ApiOperation(value = "获取教师所在科目列表")
    @GetMapping("/findTeacherSubjets")
    public Object findTeacherSubjets(){
        SysUser sysUser = sysUserFeignService.queryUserInfo();
        if(Objects.isNull(sysUser)){
            return failed(HttpStatus.FORBIDDEN,"请登录");
        }
        return succeed(subjectService.findTeacherSubjects(sysUser.getId()));
    }

    @ApiOperation(value = "获取子集科目列表")
    @GetMapping("/findSubSubjects")
    public Object findSubSubjects(Integer tenantId){
        if(tenantId == null){
            tenantId = TenantIdThreadLocal.get();
        }
        return succeed(subjectService.findSubSubjects(tenantId));
    }

}
