Skip to content

Commit

Permalink
fix: 제출 이력이 없는 과제도 포함하도록 수정 (#674)
Browse files Browse the repository at this point in the history
* fix: 제출 이력이 없는 과제도 포함하도록 수정

* remove: 사용하지 않는 레포지토리 제거

* refactor: 기존 메서드 활용하도록 수정

* fix: 과제 없는 경우 발생하는 에러 수정
  • Loading branch information
Sangwook02 authored Aug 23, 2024
1 parent 593413f commit 05017d6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.gdschongik.gdsc.domain.study.dao.AttendanceRepository;
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.Attendance;
import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
Expand All @@ -27,7 +26,6 @@
public class StudentStudyDetailService {

private final MemberUtil memberUtil;
private final StudyRepository studyRepository;
private final StudyHistoryRepository studyHistoryRepository;
private final AssignmentHistoryRepository assignmentHistoryRepository;
private final StudyDetailRepository studyDetailRepository;
Expand All @@ -39,13 +37,17 @@ 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 ->
studyDetail.getAssignment().isOpen() && 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, getSubmittedAssignment(assignmentHistories, studyDetail)))
.toList();

return AssignmentDashboardResponse.of(studyHistory.getRepositoryLink(), isAnySubmitted, submittableAssignments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ public void validateSubmittable(LocalDateTime now) {

// 데이터 전달 로직

public boolean isOpen() {
return status == OPEN;
}

public boolean isCancelled() {
return status == CANCELLED;
}
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 05017d6

Please sign in to comment.