diff --git a/src/main/java/com/waruru/areyouhere/attendance/controller/AttendanceController.java b/src/main/java/com/waruru/areyouhere/attendance/controller/AttendanceController.java index 1181cb4..796e6d8 100644 --- a/src/main/java/com/waruru/areyouhere/attendance/controller/AttendanceController.java +++ b/src/main/java/com/waruru/areyouhere/attendance/controller/AttendanceController.java @@ -7,6 +7,7 @@ import com.waruru.areyouhere.attendance.dto.UpdateAttendanceRequestDto; import com.waruru.areyouhere.attendance.exception.DuplicateAuthCodeAttendException; import com.waruru.areyouhere.attendance.service.AttendanceService; +import com.waruru.areyouhere.attendance.service.dto.CurrentSessionAttendeeAttendance; import com.waruru.areyouhere.attendee.service.AttendeeService; import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo; import com.waruru.areyouhere.common.annotation.LoginRequired; @@ -102,6 +103,12 @@ ResponseEntity getCurrentAttendances(@RequestParam("cour return ResponseEntity.ok(new CurrentAttendanceCount(currentAttendance, total)); } + @LoginRequired + @GetMapping("/detail") + ResponseEntity getCurrentSessionAttendeeAttendance(@RequestParam("authCode") String authCode){ + return ResponseEntity.ok(authCodeService.getCurrentSessionAttendanceInfo(authCode)); + } + private String encodeCookieValue(String string){ return Base64.getEncoder().encodeToString((string).getBytes()); diff --git a/src/main/java/com/waruru/areyouhere/attendance/domain/repository/AttendanceRedisRepository.java b/src/main/java/com/waruru/areyouhere/attendance/domain/repository/AttendanceRedisRepository.java index bd924e2..c4e6f76 100644 --- a/src/main/java/com/waruru/areyouhere/attendance/domain/repository/AttendanceRedisRepository.java +++ b/src/main/java/com/waruru/areyouhere/attendance/domain/repository/AttendanceRedisRepository.java @@ -20,6 +20,10 @@ public boolean isAlreadyAttended(String authCode, AttendeeRedisData attendeeInfo return attendedMembers == null || attendedMembers.contains(attendeeInfo.getId()); } + public Set getAttendees(String authCode){ + return redisTemplate.opsForSet().members(ATTENDANCE_KEY + authCode); + } + public void setAttend(String authCode, AttendeeRedisData attendeeInfo){ redisTemplate.opsForSet().add(ATTENDANCE_KEY + authCode, attendeeInfo.getId()); } diff --git a/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceService.java b/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceService.java index 56b80c2..9037f46 100644 --- a/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceService.java +++ b/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceService.java @@ -1,7 +1,6 @@ package com.waruru.areyouhere.attendance.service; import com.waruru.areyouhere.attendance.dto.UpdateAttendance; -import com.waruru.areyouhere.attendance.dto.UpdateAttendanceRequestDto; import com.waruru.areyouhere.attendance.service.dto.AttendanceCount; import java.util.List; @@ -13,7 +12,4 @@ public interface AttendanceService { public void setAttendanceStatuses(Long sessionId , List updateAttendances); public int currentAttendance(Long sessionId); - - - } diff --git a/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceServiceImpl.java b/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceServiceImpl.java index 898f095..a033f19 100644 --- a/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceServiceImpl.java +++ b/src/main/java/com/waruru/areyouhere/attendance/service/AttendanceServiceImpl.java @@ -4,19 +4,15 @@ import com.waruru.areyouhere.attendance.domain.entity.Attendance; import com.waruru.areyouhere.attendance.domain.repository.AttendanceRepository; import com.waruru.areyouhere.attendance.dto.UpdateAttendance; -import com.waruru.areyouhere.attendance.dto.UpdateAttendanceRequestDto; import com.waruru.areyouhere.attendance.service.dto.AttendanceCount; import com.waruru.areyouhere.attendee.domain.entity.Attendee; import com.waruru.areyouhere.attendee.domain.repository.AttendeeRepository; import com.waruru.areyouhere.session.domain.entity.Session; -import com.waruru.areyouhere.session.domain.repository.AuthCodeRedisRepository; import com.waruru.areyouhere.session.domain.repository.SessionRepository; import com.waruru.areyouhere.session.exception.SessionIdNotFoundException; import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.core.SetOperations; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -113,4 +109,6 @@ public int currentAttendance(Long sessionId){ } } + + } diff --git a/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeService.java b/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeService.java index 3ab858e..8200a81 100644 --- a/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeService.java +++ b/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeService.java @@ -1,5 +1,6 @@ package com.waruru.areyouhere.attendance.service; +import com.waruru.areyouhere.attendance.service.dto.CurrentSessionAttendeeAttendance; import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo; import com.waruru.areyouhere.course.domain.entity.Course; import com.waruru.areyouhere.session.domain.entity.Session; @@ -16,4 +17,6 @@ public interface AuthCodeService { public String createAuthCode(Course course, Session sessionId, LocalDateTime currentTime); public void deactivate(String authCode); + + public CurrentSessionAttendeeAttendance getCurrentSessionAttendanceInfo(String authCode); } diff --git a/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeServiceImpl.java b/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeServiceImpl.java index 92b4454..f22be17 100644 --- a/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeServiceImpl.java +++ b/src/main/java/com/waruru/areyouhere/attendance/service/AuthCodeServiceImpl.java @@ -3,6 +3,7 @@ import com.waruru.areyouhere.attendance.domain.entity.AttendeeRedisData; import com.waruru.areyouhere.attendance.domain.repository.AttendanceRedisRepository; import com.waruru.areyouhere.attendance.exception.AlreadyAttendException; +import com.waruru.areyouhere.attendance.service.dto.CurrentSessionAttendeeAttendance; import com.waruru.areyouhere.attendee.domain.entity.Attendee; import com.waruru.areyouhere.attendee.domain.repository.AttendeeRepository; import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo; @@ -17,8 +18,10 @@ import com.waruru.areyouhere.session.exception.StudentNameNotFoundException; import com.waruru.areyouhere.session.service.dto.AuthCodeInfo; import java.time.LocalDateTime; +import java.util.LinkedList; import java.util.List; import java.util.Optional; +import java.util.Set; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -131,4 +134,26 @@ public void deactivate(String authCode){ } + public CurrentSessionAttendeeAttendance getCurrentSessionAttendanceInfo(String authCode){ + AuthCode authCodeData = authCodeRedisRepository.findById(authCode) + .orElseThrow(AuthCodeNotFoundException::new); + List attendees = new LinkedList<>(); + List absentees = new LinkedList<>(); + Set attendeesChecker = attendanceRedisRepository.getAttendees(authCode); + authCodeData.getAttendees() + .forEach(att -> { + if(attendeesChecker.contains(att.getId())){ + attendees.add(att); + }else{ + absentees.add(att); + } + }); + return CurrentSessionAttendeeAttendance.builder() + .attendees(attendees) + .absentees(absentees) + .build(); + } + + + } diff --git a/src/main/java/com/waruru/areyouhere/attendance/service/dto/CurrentSessionAttendanceInfo.java b/src/main/java/com/waruru/areyouhere/attendance/service/dto/CurrentSessionAttendeeAttendance.java similarity index 50% rename from src/main/java/com/waruru/areyouhere/attendance/service/dto/CurrentSessionAttendanceInfo.java rename to src/main/java/com/waruru/areyouhere/attendance/service/dto/CurrentSessionAttendeeAttendance.java index 110a043..9ef691c 100644 --- a/src/main/java/com/waruru/areyouhere/attendance/service/dto/CurrentSessionAttendanceInfo.java +++ b/src/main/java/com/waruru/areyouhere/attendance/service/dto/CurrentSessionAttendeeAttendance.java @@ -1,5 +1,6 @@ package com.waruru.areyouhere.attendance.service.dto; +import com.waruru.areyouhere.attendance.domain.entity.AttendeeRedisData; import java.util.List; import lombok.AccessLevel; import lombok.Builder; @@ -8,12 +9,12 @@ @Getter @NoArgsConstructor(access = AccessLevel.PRIVATE) -public class CurrentSessionAttendanceInfo { - private List attendees; - private List absentees; +public class CurrentSessionAttendeeAttendance { + private List attendees; + private List absentees; @Builder - public CurrentSessionAttendanceInfo(List attendees, List absentees) { + public CurrentSessionAttendeeAttendance(List attendees, List absentees) { this.attendees = attendees; this.absentees = absentees; }