Skip to content
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

fix: 레포지토리 입력 API path variable 수정 #735

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public class StudentStudyHistoryController {
private final StudentStudyHistoryService studentStudyHistoryService;

@Operation(summary = "레포지토리 입력", description = "레포지토리를 입력합니다. 이미 제출한 과제가 있다면 수정할 수 없습니다.")
@PutMapping("/{studyHistoryId}/repository")
@PutMapping("/{studyId}/repository")
public ResponseEntity<Void> updateRepository(
@PathVariable Long studyHistoryId, @Valid @RequestBody RepositoryUpdateRequest request) throws IOException {
studentStudyHistoryService.updateRepository(studyHistoryId, request);
@PathVariable Long studyId, @Valid @RequestBody RepositoryUpdateRequest request) throws IOException {
studentStudyHistoryService.updateRepository(studyId, request);
return ResponseEntity.ok().build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.gdschongik.gdsc.domain.study.dao.AssignmentHistoryRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyHistoryRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyRepository;
import com.gdschongik.gdsc.domain.study.domain.AssignmentHistory;
import com.gdschongik.gdsc.domain.study.domain.AssignmentHistoryGrader;
import com.gdschongik.gdsc.domain.study.domain.AssignmentSubmissionFetcher;
Expand Down Expand Up @@ -43,14 +44,15 @@ public class StudentStudyHistoryService {
private final StudyHistoryValidator studyHistoryValidator;
private final StudyAssignmentHistoryValidator studyAssignmentHistoryValidator;
private final AssignmentHistoryGrader assignmentHistoryGrader;
private final StudyRepository studyRepository;

@Transactional
public void updateRepository(Long studyHistoryId, RepositoryUpdateRequest request) throws IOException {
public void updateRepository(Long studyId, RepositoryUpdateRequest request) throws IOException {
Member currentMember = memberUtil.getCurrentMember();
Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND));
StudyHistory studyHistory = studyHistoryRepository
.findById(studyHistoryId)
.findByStudentAndStudy(currentMember, study)
Comment on lines +52 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateRepository 메서드 구현 변경 승인 및 개선 제안

studyId를 사용하여 Study 객체를 조회하고, 이를 통해 StudyHistory를 가져오는 변경이 적절합니다.

개선 제안:

  1. Study 조회 실패 시 로그 추가
  2. StudyHistory 조회 실패 시 더 자세한 예외 메시지 제공

다음과 같이 코드를 개선할 수 있습니다:

-        Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND));
+        Study study = studyRepository.findById(studyId)
+                .orElseThrow(() -> {
+                    log.error("Study not found with id: {}", studyId);
+                    return new CustomException(STUDY_NOT_FOUND);
+                });
         StudyHistory studyHistory = studyHistoryRepository
                 .findByStudentAndStudy(currentMember, study)
-                .orElseThrow(() -> new CustomException(STUDY_HISTORY_NOT_FOUND));
+                .orElseThrow(() -> new CustomException(STUDY_HISTORY_NOT_FOUND, 
+                        String.format("StudyHistory not found for member %s and study %d", currentMember.getId(), studyId)));

Committable suggestion was skipped due to low confidence.

.orElseThrow(() -> new CustomException(STUDY_HISTORY_NOT_FOUND));
Study study = studyHistory.getStudy();

boolean isAnyAssignmentSubmitted =
assignmentHistoryRepository.existsSubmittedAssignmentByMemberAndStudy(currentMember, study);
Expand Down