diff --git a/src/main/java/org/cotato/csquiz/api/attendance/dto/AttendanceRecordResponse.java b/src/main/java/org/cotato/csquiz/api/attendance/dto/AttendanceRecordResponse.java index 30806620..933b4b5c 100644 --- a/src/main/java/org/cotato/csquiz/api/attendance/dto/AttendanceRecordResponse.java +++ b/src/main/java/org/cotato/csquiz/api/attendance/dto/AttendanceRecordResponse.java @@ -3,21 +3,22 @@ import java.util.List; import java.util.Map; import java.util.stream.Collectors; -import org.cotato.csquiz.api.admin.dto.MemberInfoResponse; import org.cotato.csquiz.domain.attendance.entity.AttendanceRecord; import org.cotato.csquiz.domain.attendance.enums.AttendanceStatus; import org.cotato.csquiz.domain.attendance.enums.AttendanceType; +import org.cotato.csquiz.domain.auth.entity.Member; +import org.cotato.csquiz.domain.auth.enums.MemberRole; public record AttendanceRecordResponse( - MemberInfoResponse memberInfo, + AttendanceMemberInfo memberInfo, List attendanceInfos, AttendanceStatistic statistic ) { - public static AttendanceRecordResponse of(MemberInfoResponse memberInfo, List attendanceRecords, + public static AttendanceRecordResponse of(Member member, List attendanceRecords, Integer totalAttendance) { return new AttendanceRecordResponse( - memberInfo, + AttendanceMemberInfo.from(member), attendanceRecords.stream() .map(AttendanceInfoResponse::from) .toList(), @@ -25,6 +26,20 @@ public static AttendanceRecordResponse of(MemberInfoResponse memberInfo, List generateAttendanceResponses(List attendances){ + public List generateAttendanceResponses(List attendances) { Map> recordsByMemberId = attendanceRecordRepository.findAllByAttendanceIdsInQuery( attendances).stream() .collect(Collectors.groupingBy(AttendanceRecord::getMemberId)); + Map memberMap = memberService.findActiveMember().stream() + .collect(Collectors.toMap(Member::getId, member -> member)); + return recordsByMemberId.entrySet().stream() .map(entry -> { - MemberInfoResponse memberInfo = memberService.findMemberInfo(entry.getKey()); - return AttendanceRecordResponse.of(memberInfo, entry.getValue(), attendances.size()); + Member member = memberMap.get(entry.getKey()); + if (member == null) { + return null; + } + return AttendanceRecordResponse.of(member, entry.getValue(), + attendances.size()); }) + .filter(Objects::nonNull) .toList(); + } } diff --git a/src/main/java/org/cotato/csquiz/domain/auth/enums/MemberRole.java b/src/main/java/org/cotato/csquiz/domain/auth/enums/MemberRole.java index cef0d65e..b08d2aa0 100644 --- a/src/main/java/org/cotato/csquiz/domain/auth/enums/MemberRole.java +++ b/src/main/java/org/cotato/csquiz/domain/auth/enums/MemberRole.java @@ -1,5 +1,7 @@ package org.cotato.csquiz.domain.auth.enums; +import java.util.ArrayList; +import java.util.List; import org.cotato.csquiz.common.error.exception.AppException; import org.cotato.csquiz.common.error.ErrorCode; import java.util.Arrays; @@ -27,4 +29,8 @@ public static MemberRole fromKey(final String key) { .findFirst() .orElseThrow(() -> new AppException(ErrorCode.ENUM_NOT_RESOLVED)); } + + public static List activeMemberRoles() { + return List.of(ADMIN, EDUCATION, MEMBER); + } } diff --git a/src/main/java/org/cotato/csquiz/domain/auth/service/MemberService.java b/src/main/java/org/cotato/csquiz/domain/auth/service/MemberService.java index 0c1ad3aa..b097d985 100644 --- a/src/main/java/org/cotato/csquiz/domain/auth/service/MemberService.java +++ b/src/main/java/org/cotato/csquiz/domain/auth/service/MemberService.java @@ -1,6 +1,8 @@ package org.cotato.csquiz.domain.auth.service; import jakarta.persistence.EntityNotFoundException; +import java.util.ArrayList; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.cotato.csquiz.api.admin.dto.MemberInfoResponse; @@ -13,6 +15,7 @@ import org.cotato.csquiz.common.error.exception.AppException; import org.cotato.csquiz.common.error.exception.ImageException; import org.cotato.csquiz.domain.auth.entity.Member; +import org.cotato.csquiz.domain.auth.enums.MemberRole; import org.cotato.csquiz.domain.auth.repository.MemberRepository; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.stereotype.Service; @@ -125,4 +128,8 @@ public MemberInfo getMemberInfo(Long memberId) { .orElseThrow(() -> new EntityNotFoundException("해당 멤버를 찾을 수 없습니다.")); return MemberInfo.of(findMember, findBackFourNumber(findMember)); } + + public List findActiveMember() { + return memberRepository.findAllByRoleInQuery(MemberRole.activeMemberRoles()); + } }