Skip to content

Commit

Permalink
fix: 제출 이력이 없는 과제도 포함하도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Aug 23, 2024
1 parent 986dda9 commit 1886587
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,21 @@ public AssignmentDashboardResponse getSubmittableAssignments(Long studyId) {
StudyHistory studyHistory = studyHistoryRepository
.findByStudentAndStudyId(currentMember, studyId)
.orElseThrow(() -> new CustomException(ErrorCode.STUDY_HISTORY_NOT_FOUND));

List<AssignmentHistory> assignmentHistories =
assignmentHistoryRepository.findAssignmentHistoriesByStudentAndStudy(currentMember, studyId);
List<StudyDetail> studyDetails = studyDetailRepository.findAllByStudyIdOrderByWeekAsc(studyId).stream()
.filter(StudyDetail::isAssignmentDeadlineRemaining)
.toList();

boolean isAnySubmitted = assignmentHistories.stream().anyMatch(AssignmentHistory::isSubmitted);
List<AssignmentSubmittableDto> submittableAssignments = assignmentHistories.stream()
.filter(assignmentHistory -> assignmentHistory.getStudyDetail().isAssignmentDeadlineRemaining())
.map(AssignmentSubmittableDto::from)
List<AssignmentSubmittableDto> submittableAssignments = studyDetails.stream()
.map(studyDetail -> AssignmentSubmittableDto.of(
studyDetail,
assignmentHistories.stream()
.filter(assignmentHistory ->
assignmentHistory.getStudyDetail().equals(studyDetail))
.findAny()
.orElse(null)))
.toList();

return AssignmentDashboardResponse.of(studyHistory.getRepositoryLink(), isAnySubmitted, submittableAssignments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@ public record AssignmentSubmittableDto(
@Nullable @Schema(description = "마감 기한") LocalDateTime deadline,
@Nullable @Schema(description = "과제 제출 링크") String submissionLink,
@Nullable @Schema(description = "과제 제출 실패 사유") SubmissionFailureType submissionFailureType) {
public static AssignmentSubmittableDto from(AssignmentHistory assignmentHistory) {
StudyDetail studyDetail = assignmentHistory.getStudyDetail();
public static AssignmentSubmittableDto of(StudyDetail studyDetail, AssignmentHistory assignmentHistory) {
Assignment assignment = studyDetail.getAssignment();

if (assignment.isCancelled()) {
return cancelledAssignment(studyDetail, assignment);
}

if (assignmentHistory == null) {
return notSubmittedAssignment(studyDetail, assignment);
}

return new AssignmentSubmittableDto(
studyDetail.getId(),
assignment.getStatus(),
Expand All @@ -37,13 +40,24 @@ public static AssignmentSubmittableDto from(AssignmentHistory assignmentHistory)
assignment.getDescriptionLink(),
assignment.getDeadline(),
assignmentHistory.getSubmissionLink(),
assignmentHistory.getSubmissionFailureType() == null
? null
: assignmentHistory.getSubmissionFailureType());
assignmentHistory.getSubmissionFailureType());
}

private static AssignmentSubmittableDto cancelledAssignment(StudyDetail studyDetail, Assignment assignment) {
return new AssignmentSubmittableDto(
studyDetail.getId(), assignment.getStatus(), studyDetail.getWeek(), null, null, null, null, null, null);
}

private static AssignmentSubmittableDto notSubmittedAssignment(StudyDetail studyDetail, Assignment assignment) {
return new AssignmentSubmittableDto(
studyDetail.getId(),
assignment.getStatus(),
studyDetail.getWeek(),
assignment.getTitle(),
AssignmentSubmissionStatus.FAILURE,
assignment.getDescriptionLink(),
assignment.getDeadline(),
null,
SubmissionFailureType.NOT_SUBMITTED);
}
}

0 comments on commit 1886587

Please sign in to comment.