From b95449407b4bde0853365683e2fc49f1a16602b6 Mon Sep 17 00:00:00 2001 From: gikhoon Date: Thu, 1 Aug 2024 17:31:02 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EC=B6=9C=EC=84=9D=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=20=EA=B8=B0=EB=8A=A5=EC=9D=84=20=EB=8B=A4=EB=A5=B8=20?= =?UTF-8?q?=EC=84=9C=EB=B9=84=EC=8A=A4=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - AdminService로 부터 출석기록 정보가 사용되는 부분을 RecordService로 분리 --- .../service/AttendanceAdminService.java | 20 +--------- .../service/AttendanceRecordService.java | 38 +++++++++++++++++++ 2 files changed, 40 insertions(+), 18 deletions(-) create mode 100644 src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceRecordService.java diff --git a/src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceAdminService.java b/src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceAdminService.java index 3b1a0cf4..8affe004 100644 --- a/src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceAdminService.java +++ b/src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceAdminService.java @@ -6,11 +6,8 @@ import java.time.LocalDateTime; import java.time.LocalTime; import java.util.List; -import java.util.Map; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.cotato.csquiz.api.admin.dto.MemberInfoResponse; import org.cotato.csquiz.api.attendance.dto.AttendanceRecordResponse; import org.cotato.csquiz.api.attendance.dto.UpdateAttendanceRequest; import org.cotato.csquiz.api.session.dto.AddSessionRequest.AttendanceDeadLine; @@ -18,10 +15,7 @@ import org.cotato.csquiz.common.error.exception.AppException; import org.cotato.csquiz.domain.attendance.embedded.Location; import org.cotato.csquiz.domain.attendance.entity.Attendance; -import org.cotato.csquiz.domain.attendance.entity.AttendanceRecord; -import org.cotato.csquiz.domain.attendance.repository.AttendanceRecordRepository; import org.cotato.csquiz.domain.attendance.repository.AttendanceRepository; -import org.cotato.csquiz.domain.auth.service.MemberService; import org.cotato.csquiz.domain.generation.entity.Session; import org.cotato.csquiz.domain.generation.repository.SessionRepository; import org.springframework.stereotype.Service; @@ -34,9 +28,8 @@ public class AttendanceAdminService { private final AttendanceRepository attendanceRepository; - private final AttendanceRecordRepository attendanceRecordRepository; + private final AttendanceRecordService attendanceRecordService; private final SessionRepository sessionRepository; - private final MemberService memberService; @Transactional public void addAttendance(Session session, LocalDate localDate, Location location, @@ -90,16 +83,7 @@ public List findAttendanceRecords(Long generationId, I List attendances = attendanceRepository.findAllBySessionIdsInQuery(sessionIds).stream() .toList(); - Map> recordsByMemberId = attendanceRecordRepository.findAllByAttendanceIdsInQuery( - attendances).stream() - .collect(Collectors.groupingBy(AttendanceRecord::getMemberId)); - - return recordsByMemberId.entrySet().stream() - .map(entry -> { - MemberInfoResponse memberInfo = memberService.findMemberInfo(entry.getKey()); - return AttendanceRecordResponse.of(memberInfo, entry.getValue(), attendances.size()); - }) - .toList(); + return attendanceRecordService.generateAttendanceResponses(attendances); } private boolean checkAttendanceTimeValid(LocalTime startTime, LocalTime endTime) { diff --git a/src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceRecordService.java b/src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceRecordService.java new file mode 100644 index 00000000..f40be402 --- /dev/null +++ b/src/main/java/org/cotato/csquiz/domain/attendance/service/AttendanceRecordService.java @@ -0,0 +1,38 @@ +package org.cotato.csquiz.domain.attendance.service; + +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.cotato.csquiz.api.admin.dto.MemberInfoResponse; +import org.cotato.csquiz.api.attendance.dto.AttendanceRecordResponse; +import org.cotato.csquiz.domain.attendance.entity.Attendance; +import org.cotato.csquiz.domain.attendance.entity.AttendanceRecord; +import org.cotato.csquiz.domain.attendance.repository.AttendanceRecordRepository; +import org.cotato.csquiz.domain.auth.service.MemberService; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +@Transactional(readOnly = true) +@Slf4j +public class AttendanceRecordService { + + private final AttendanceRecordRepository attendanceRecordRepository; + private final MemberService memberService; + + public List generateAttendanceResponses(List attendances){ + Map> recordsByMemberId = attendanceRecordRepository.findAllByAttendanceIdsInQuery( + attendances).stream() + .collect(Collectors.groupingBy(AttendanceRecord::getMemberId)); + + return recordsByMemberId.entrySet().stream() + .map(entry -> { + MemberInfoResponse memberInfo = memberService.findMemberInfo(entry.getKey()); + return AttendanceRecordResponse.of(memberInfo, entry.getValue(), attendances.size()); + }) + .toList(); + } +}