-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 답안 자동 채점 로직 (gradeExamResult) 및 총점 검증 로직 (verifyTotalScore) 구현 - ExamResult와 ExamScore 클래스 개선 (상태 관리 강화, 불필요 필드 제거 등) - ExamResultRepository에 채점 상태 및 시간 초과 시험 조회 쿼리 추가 - AutoGradingScheduler로 시험 자동 제출 및 채점 기능 구현 - 채점 관련 예외 처리 및 오류 코드 추가
- Loading branch information
Showing
16 changed files
with
531 additions
and
44 deletions.
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
src/main/java/com/example/epari/exam/controller/GradingController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package com.example.epari.exam.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.access.prepost.PreAuthorize; | ||
import org.springframework.web.bind.annotation.ExceptionHandler; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.epari.exam.exception.GradingException; | ||
import com.example.epari.exam.exception.GradingNotPossibleException; | ||
import com.example.epari.exam.exception.InvalidScoreException; | ||
import com.example.epari.exam.service.GradingService; | ||
import com.example.epari.exam.service.GradingService.ScoreStatistics; | ||
import com.example.epari.global.annotation.CurrentUserEmail; | ||
import com.example.epari.global.exception.ErrorCode; | ||
import com.example.epari.global.exception.ErrorResponse; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
|
||
/** | ||
* 시험 채점 및 성적 통계 관련 요청을 처리하는 Controller | ||
*/ | ||
@Slf4j | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/courses/{courseId}/exams/{examId}/grades") | ||
public class GradingController { | ||
|
||
private final GradingService gradingService; | ||
|
||
/** | ||
* 시험 결과 채점 요청 | ||
* @param courseId 강의 ID | ||
* @param examId 시험 ID | ||
* @param resultId 채점할 시험 결과 ID | ||
* @param instructorEmail 강사 이메일 | ||
* @return 채점 완료 응답 | ||
*/ | ||
@PostMapping("/results/{resultId}") | ||
@PreAuthorize("hasRole('INSTRUCTOR') and @courseSecurityChecker.checkInstructorAccess(#courseId, #instructorEmail)") | ||
public ResponseEntity<Void> gradeExam( | ||
@PathVariable Long courseId, | ||
@PathVariable Long examId, | ||
@PathVariable Long resultId, | ||
@CurrentUserEmail String instructorEmail) { | ||
|
||
log.info("Grading request - courseId: {}, examId: {}, resultId: {}", courseId, examId, resultId); | ||
gradingService.gradeExamResult(resultId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
/** | ||
* 평균 점수 조회 | ||
* @param courseId 강의 ID | ||
* @param examId 시험 ID | ||
* @param instructorEmail 강사 이메일 | ||
* @return 평균 점수 | ||
*/ | ||
@GetMapping("/average") | ||
@PreAuthorize("hasRole('INSTRUCTOR') and @courseSecurityChecker.checkInstructorAccess(#courseId, #instructorEmail)") | ||
public ResponseEntity<Double> getAverageScore( | ||
@PathVariable Long courseId, | ||
@PathVariable Long examId, | ||
@CurrentUserEmail String instructorEmail) { | ||
|
||
log.info("Retrieving average score - courseId: {}, examId: {}", courseId, examId); | ||
double averageScore = gradingService.calculateAverageScore(examId); | ||
return ResponseEntity.ok(averageScore); | ||
} | ||
|
||
/** | ||
* 최고/최저 점수 통계 조회 | ||
* @param courseId 강의 ID | ||
* @param examId 시험 ID | ||
* @param instructorEmail 강사 이메일 | ||
* @return 점수 통계 정보 | ||
*/ | ||
@GetMapping("/statistics") | ||
@PreAuthorize("hasRole('INSTRUCTOR') and @courseSecurityChecker.checkInstructorAccess(#courseId, #instructorEmail)") | ||
public ResponseEntity<ScoreStatistics> getScoreStatistics( | ||
@PathVariable Long courseId, | ||
@PathVariable Long examId, | ||
@CurrentUserEmail String instructorEmail) { | ||
|
||
log.info("Retrieving score statistics - courseId: {}, examId: {}", courseId, examId); | ||
ScoreStatistics statistics = gradingService.calculateScoreStatistics(examId); | ||
return ResponseEntity.ok(statistics); | ||
} | ||
|
||
@ExceptionHandler(GradingException.class) | ||
public ResponseEntity<ErrorResponse> handleGradingException(GradingException e) { | ||
log.error("채점 처리 중 오류 발생", e); | ||
return ErrorResponse.toResponseEntity(ErrorCode.GRADING_FAILED); | ||
} | ||
|
||
@ExceptionHandler(GradingNotPossibleException.class) | ||
public ResponseEntity<ErrorResponse> handleGradingNotPossibleException(GradingNotPossibleException e) { | ||
log.error("채점 불가능한 상태", e); | ||
return ErrorResponse.toResponseEntity(ErrorCode.EXAM_NOT_SUBMITTED); | ||
} | ||
|
||
@ExceptionHandler(InvalidScoreException.class) | ||
public ResponseEntity<ErrorResponse> handleInvalidScoreException(InvalidScoreException e) { | ||
log.error("유효하지 않은 점수", e); | ||
return ErrorResponse.toResponseEntity(ErrorCode.INVALID_SCORE_VALUE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/main/java/com/example/epari/exam/exception/GradingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.epari.exam.exception; | ||
|
||
public class GradingException extends RuntimeException { | ||
|
||
private static final long serialVersionUID = 1L; | ||
|
||
public GradingException(String message) { | ||
super(message); | ||
} | ||
|
||
public GradingException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} | ||
|
8 changes: 8 additions & 0 deletions
8
src/main/java/com/example/epari/exam/exception/GradingNotPossibleException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.epari.exam.exception; | ||
|
||
public class GradingNotPossibleException extends GradingException { | ||
|
||
public GradingNotPossibleException(String message) { | ||
super(message); | ||
} | ||
} |
Oops, something went wrong.