package test05.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import test05.pojo.Course;
import test05.pojo.Result;
import test05.pojo.Score;
import test05.pojo.Student;
import test05.service.ScoreService;

@RestController
@RequestMapping("/scoreAction")
public class ScoreController {
    ScoreService scoreService;
    @Autowired
    public ScoreController(ScoreService scoreService) {
        this.scoreService = scoreService;
    }
    @RequestMapping("/get")
    public Result getScore(int studentId, int courseId) {
        return scoreService.getScore(new Student(studentId), new Course(courseId));
    }
    @RequestMapping("/update")
    public Result updateScore(Score score) {
        return scoreService.updateScore(score);
    }
    @RequestMapping("add")
    public Result addScore(Student student, Course course, Float score) {
        return scoreService.addScore(student, course, score);
    }
    @RequestMapping("/delete")
    public Result deleteScore(Score score) {
        return scoreService.deleteScore(score);
    }
    @RequestMapping("/getByStu")
    public Result getScoreByStu(String studentCode) {
        Student student = new Student();
        student.setCode(studentCode);
        return scoreService.getStudentScore(student);
    }
}
