package rd.controller.score;

import cn.dev33.satoken.annotation.SaCheckRole;
import rd.data.dto.score.CourseScoreInfoDto;
import rd.data.model.response.Response;
import rd.service.score.ScoreService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher/score")
public class TeacherScoreController {

    private final ScoreService scoreService;

    public TeacherScoreController(ScoreService scoreService) {
        this.scoreService = scoreService;
    }

    @SaCheckRole("TEACHER")
    @RequestMapping("/list-students")
    public Response<List<CourseScoreInfoDto>> listStudents(@RequestParam("course") Long courseId,
                                                           @RequestParam("term") String term
    ) {
        var result = scoreService.getCourseTermAllSelectedStudentScore(courseId, term);

        return Response.success(result);
    }

    @SaCheckRole("TEACHER")
    @PostMapping("/update")
    public Response<Object> update(@RequestParam(value = "scoreId", required = false) Long scoreId,
                                   @RequestParam("course") Long courseId, @RequestParam("term") String term,
                                   @RequestBody CourseScoreInfoDto courseScoreInfoDto) {

        scoreService.insertOrUpdateScore(scoreId, courseId, term, courseScoreInfoDto);

        return Response.success();
    }
}


