package com.ruoyi.web.controller.test.gl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.test.domain.Subject;
import com.ruoyi.test.domain.Vo.SubjectVo;
import com.ruoyi.test.seriver.ISubjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "管理端学科管理")
@RestController
@RequestMapping("/gl/subject")
public class SubjectController {

    @Autowired
    private ISubjectService iSubjectService;

    @ApiOperation("学科列表")
    @GetMapping("selectAll")
    public R<IPage<Subject>> selectAll(int pagenum){
        return R.ok(iSubjectService.selectAll(pagenum));
    }

    @ApiOperation("根据年级查询学科")
    @GetMapping("selectGrade")
    public R<IPage<Subject>> selectGrade(String Grade,int pagenum){
        return R.ok(iSubjectService.selectGrade(Grade,pagenum));
    }

    @ApiOperation("添加学科")
    @PostMapping("addSubject")
    public R<String> addSubject(@RequestBody SubjectVo subjectVo){
        if(iSubjectService.addSubject(subjectVo)==2){
            return R.fail("该年级已有该学科！");
        }else if(iSubjectService.addSubject(subjectVo)!=0){
            return R.ok("添加成功！");
        }
        return R.fail("添加失败！");
    }
}
