diff --git a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java index 9ea4580b2..39da17313 100644 --- a/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java +++ b/src/main/java/com/gdschongik/gdsc/domain/study/dto/response/StudyStudentResponse.java @@ -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(), @@ -67,4 +57,17 @@ private static boolean isOutstandingStudent( return studyAchievements.stream() .anyMatch(studyAchievement -> studyAchievement.getAchievementType() == achievementType); } + + private static long countAssignmentByStatus( + List assignments, AssignmentSubmissionStatusResponse status) { + return assignments.stream() + .filter(studyTodoResponse -> studyTodoResponse.assignmentSubmissionStatus() == status) + .count(); + } + + private static long countAttendanceByStatus(List attendances, AttendanceStatusResponse status) { + return attendances.stream() + .filter(studyTodoResponse -> studyTodoResponse.attendanceStatus() == status) + .count(); + } }