-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 시험 문제 자동 채점기능 구현 #99
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
57aa431
FEAT: 자동채점 기능 로직 구현
hyerin315 6278abe
FEAT: 답안 검증 로직 구현
hyerin315 18afeaa
FEAT: ExamResult 및 ExamScore 클래스 개선
hyerin315 f6002a9
FEAT: GradingService에 시험 채점 기능 구현
hyerin315 ae72bac
FEAT: 채점기능 엔드포인트 구현
hyerin315 ea86596
FIX: log import 오류 해결
hyerin315 d32cb17
FEAT: ExamResultRepository 조회 쿼리 및 AutoGradingScheduler 채점 기능 추가
hyerin315 c7bc57d
FEAT: 채점 관리 ErrorCode 및 예외 클래스 생성
hyerin315 c9419f0
REFACTOR: 불필요한 문자, 공백 삭제 및 주석 수정
hyerin315 c82be21
FEAT: 예외 처리 로직 추가
hyerin315 c64f9d8
Merge branch 'main' into feature/93-auto-grading-system
hyerin315 0193672
FIX: InitData의 createExamResults 점수 업데이트 로직 수정
hyerin315 6a820d6
FIX: 시험 채점 후 총점이 저장되지 않는 오류 해결
hyerin315 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
특히 이 부분 코드가 읽기 좋고 잘 하셨네요!