Skip to content

Commit

Permalink
refactor: 중복 로직 메서드로 추출
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Oct 5, 2024
1 parent 5fa5e05 commit 223286d
Showing 1 changed file with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,11 @@ public static StudyStudentResponse of(
.filter(studyTodoResponse -> studyTodoResponse.todoType() == ATTENDANCE)
.toList();

long successAssignmentsCount = assignments.stream()
.filter(studyTodoResponse -> studyTodoResponse.assignmentSubmissionStatus() == SUCCESS)
.count();

long cancelledAssignmentsCount = assignments.stream()
.filter(studyTodoResponse -> studyTodoResponse.assignmentSubmissionStatus() == CANCELLED)
.count();
long successAssignmentsCount = countAssignmentByStatus(assignments, SUCCESS);
long cancelledAssignmentsCount = countAssignmentByStatus(assignments, CANCELLED);

long attendedCount = attendances.stream()
.filter(studyTodoResponse -> studyTodoResponse.attendanceStatus() == AttendanceStatusResponse.ATTENDED)
.count();

long cancelledAttendanceCount = attendances.stream()
.filter(studyTodoResponse -> studyTodoResponse.attendanceStatus() == AttendanceStatusResponse.CANCELLED)
.count();
long attendedCount = countAttendanceByStatus(attendances, AttendanceStatusResponse.ATTENDED);
long cancelledAttendanceCount = countAttendanceByStatus(attendances, AttendanceStatusResponse.CANCELLED);

return new StudyStudentResponse(
studyHistory.getStudent().getId(),
Expand All @@ -67,4 +57,17 @@ private static boolean isOutstandingStudent(
return studyAchievements.stream()
.anyMatch(studyAchievement -> studyAchievement.getAchievementType() == achievementType);
}

private static long countAssignmentByStatus(
List<StudyTodoResponse> assignments, AssignmentSubmissionStatusResponse status) {
return assignments.stream()
.filter(studyTodoResponse -> studyTodoResponse.assignmentSubmissionStatus() == status)
.count();
}

private static long countAttendanceByStatus(List<StudyTodoResponse> attendances, AttendanceStatusResponse status) {
return attendances.stream()
.filter(studyTodoResponse -> studyTodoResponse.attendanceStatus() == status)
.count();
}
}

0 comments on commit 223286d

Please sign in to comment.