package cn.teammodel.controller.admin.controller;

import cn.teammodel.common.R;
import cn.teammodel.controller.admin.service.CommonService;
import cn.teammodel.model.dto.admin.common.CommentDto;
import cn.teammodel.model.dto.admin.common.GCDto;
import cn.teammodel.model.entity.common.Comment;
import cn.teammodel.model.vo.admin.GradeAndClassVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
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;
import java.util.List;

@RestController
@RequestMapping("admin/common")
@Api(tags = "管理员端-公共组件")
public class CommonController {

    @Resource
    private CommonService commonService ;
    @PostMapping("getGradeAndClass")
    @ApiOperation("获取当前学校当前学段年级班级信息")
    public R<List<GradeAndClassVo>> findRecords(@Valid @RequestBody GCDto gcDto) {
        List<GradeAndClassVo> res = commonService.getGradeAndClass(gcDto);
        return R.success(res);
    }
    @PostMapping("save")
    @ApiOperation("保存评语")
    public R<Comment> saveOrUpdateComment(@Valid @RequestBody Comment comment) {
        Comment res = commonService.saveOrUpdateComment(comment);
        return R.success(res);
    }
    @PostMapping("delete")
    @ApiOperation("删除评语")
    public R<List<String>> deleteComment(@Valid @RequestBody CommentDto comment) {
        List<String> res = commonService.deleteComment(comment);
        return R.success(res);
    }
    @PostMapping("find")
    @ApiOperation("根据ID查询评语")
    public R<List<Comment>> findComment(@Valid @RequestBody Comment comment) {
        List<Comment> res = commonService.getCommentById(comment);
        return R.success(res);
    }
}
