-
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] 시험 문제 생성, 수정, 삭제 기능 구현 #74
Conversation
- test 환경에 s3 환경을 Mock 데이터로 수정
- InsturctorExamService, StudentExamService 삭제 후 ExamService에 통합 - InstuctorExamController 및 StudentExamController 삭제 후 ExamController에서 엔드포인트 관리
- 시험 목록 조회, 상세조회, 생성, 수정, 삭제 관련 엔드포인트 수정 - @PreAuthorize를 사용하여 역할별 엔드포인드 처리 구현
- 객관식/주관식 문제를 correctAnswer 하나의 필드로 관리 - 유효성 검사를 위한 validateAnswer 추가
- 시험 문제 번호를 자동으로 재정렬해주기 위한 메소드 추가
- 시험 문제 생성, 정렬, 수정, 삭제를 위한 엔드포인트 구현
- 시험 문제 생성을 요청하는 CreateQuestionRequestDto 클래스 구현 - 시험 유효성 검사, 객관식/주관식 문제 생성 기능 구현 - 객관식 문제 생성시 보기 번호 생성을 위한 ChoiceRequestDto 클래스 구현
- 시험 문제 조회, 수정 기능에 응답하는 ExamQuestionResponseDto 클래스 구현 - 시험 유효성 검사, 객관식/주관식 문제 조회 기능 구현 - 객관식 문제 조회를 위한 ChoiceResponseDto 클래스 구현
- 중복 사용되는 시험 조회 컴포넌트 구현
- ExamService를 역할 기반에서 기능 기반으로 수정하여 시험 CRUD 로직을 모두 수행할 수 있도록 수정 - ExamQuestionService로 시험 문제 CRUD 로직을 모두 수행할 수 있도록 기능 구현
- 문제 수정을 위한 UpdateQuestionRequestDto 클래스 구현
- 문제 조회를 위한 ExamQuestionRepository 구현
- Exam 클래스에서 reorderQuestionAfterDelete 메소드 기능 수정 - ExamQuestionService에서 삭제 후 남은 문제의 번호 재정렬을 처리하는 기능 구현
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.
복잡한 비즈니스 로직을 하나씩 고민하시면서 접근해보신 흔적이 느껴집니다...
중간중간 도메인에 비즈니스 로직과 검증 로직이 담겨있어 좋았습니다.
또, ExamFinder 클래스로 조회 로직을 분리해보신 것도 좋은 방식인듯 합니다!
몇가지 궁금한 점이 있어 코멘트를 남겨드리니 추후 리팩토링간 참고 및 답변 해주시면 좋겠습니다.
고생 많으셨습니다!
@PathVariable Long examId, | ||
@CurrentUserEmail String email, | ||
Authentication authentication) { | ||
String role = authentication.getAuthorities().stream() |
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.
역할을 추출하는 코드가 중복되고 있네요!
만약 역할을 추출해야하는 상황이 반복된다면, 커스텀 어노테이션을 정의해보시는 것도 좋은 방법일 것 같습니다!
@CurrentUserEmail
과 같은 방식으로요!
String description, | ||
Course course) { | ||
Exam exam = new Exam(); | ||
exam.title = title; |
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.
필드를 하나씩 지정하셨는데, 그 이유가 있을까요?
관련 필드를 전달받아 새로운 인스턴스를 반환하는 private 생성자를 사용해보시는방법은 어떻게 생각하시는지 궁금합니다!
ExamQuestion targetQuestion = questions.stream() | ||
.filter(q -> q.getId().equals(questionId)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("문제를 찾을 수 없습니다. ID: " + questionId)); |
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.
추후 커스텀 예외를 생성하여 예외 처리를 일관성 있게 유지해주시면 좋겠습니다!
|
||
public ExamQuestion toEntity(Exam exam) { | ||
// exam 유효성 검사 | ||
if (exam == null) { |
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.
이 유효성 검사가 필요한지 고민해보시면 좋겠습니다!
|
||
// 시험 목록 조회 | ||
public List<ExamResponseDto> getExams(Long courseId, String email, String role) { | ||
if (role.contains("ROLE_INSTRUCTOR")) { |
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.
getExams 메서드를 사용하여 강사와 학생의 시험 조회 기능을 모두 구현하셨군요!
이런 방식을 채택하신 이유가 궁금합니다!!
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.
제일 어려운 부분 구현하시느라 고생하셨습니다.
|
||
// 시험 문제 생성 | ||
@PostMapping | ||
@PreAuthorize("hasRole('INSTRUCTOR')") |
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.
@PreAuthorize이 동작하려면 @EnableMethodSecurity 필요한데 따로 관리하게 하셨나용? 아니시면 SecurityConfig에 SecurityConfig서 전역으로 관리하는게 좋다고 하네요 저도 컨트롤러마다 작성했는데 이 번에 수정할려구요!
- ExamController와 ExamQuestionController에서 권한 검증 방식 변경 - Exam 생성자의 객체 생성 방식을 public에서 private으로 변경
관련 이슈
목적
시험 문제 관리를 위한 생성, 수정, 삭제 기능을 구현합니다.
변경 사항
1. 객관식 및 주관식 문제 생성 기능 구현
correctAnswer
필드를 추가하여 객관식과 주관식 문제를 통합적으로 관리ChoiceRequestDto
를 통해 객관식 문제의 보기 번호 데이터를 처리하도록 구현validateAnswer
메서드를 추가하여 입력된 정답 유효성 검사2. 문제 수정 및 삭제 기능 구현
3. ExamService 및 Controller 통합
InstructorExamService
와StudentExamService
를ExamService
로 통합InstructorExamController
및StudentExamController
삭제 후ExamController
에서 엔드포인트 관리@PreAuthorize
를 활용한 역할별 접근 제어 구현스크린샷
주요 변경사항
체크리스트
공유사항
추후 업무