Skip to content

Commit

Permalink
feat: 현재 세션 출석자, 결석자 실시간 조회 API
Browse files Browse the repository at this point in the history
  • Loading branch information
SHEOMM committed Mar 29, 2024
1 parent 3d9bacc commit 27ee2e5
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -102,6 +103,12 @@ ResponseEntity<CurrentAttendanceCount> getCurrentAttendances(@RequestParam("cour
return ResponseEntity.ok(new CurrentAttendanceCount(currentAttendance, total));
}

@LoginRequired
@GetMapping("/detail")
ResponseEntity<CurrentSessionAttendeeAttendance> getCurrentSessionAttendeeAttendance(@RequestParam("authCode") String authCode){
return ResponseEntity.ok(authCodeService.getCurrentSessionAttendanceInfo(authCode));
}


private String encodeCookieValue(String string){
return Base64.getEncoder().encodeToString((string).getBytes());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public boolean isAlreadyAttended(String authCode, AttendeeRedisData attendeeInfo
return attendedMembers == null || attendedMembers.contains(attendeeInfo.getId());
}

public Set<Long> 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());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -13,7 +12,4 @@ public interface AttendanceService {

public void setAttendanceStatuses(Long sessionId , List<UpdateAttendance> updateAttendances);
public int currentAttendance(Long sessionId);



}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -113,4 +109,6 @@ public int currentAttendance(Long sessionId){
}
}



}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -131,4 +134,26 @@ public void deactivate(String authCode){

}

public CurrentSessionAttendeeAttendance getCurrentSessionAttendanceInfo(String authCode){
AuthCode authCodeData = authCodeRedisRepository.findById(authCode)
.orElseThrow(AuthCodeNotFoundException::new);
List<AttendeeRedisData> attendees = new LinkedList<>();
List<AttendeeRedisData> absentees = new LinkedList<>();
Set<Long> 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();
}



}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -8,12 +9,12 @@

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class CurrentSessionAttendanceInfo {
private List<String> attendees;
private List<String> absentees;
public class CurrentSessionAttendeeAttendance {
private List<AttendeeRedisData> attendees;
private List<AttendeeRedisData> absentees;

@Builder
public CurrentSessionAttendanceInfo(List<String> attendees, List<String> absentees) {
public CurrentSessionAttendeeAttendance(List<AttendeeRedisData> attendees, List<AttendeeRedisData> absentees) {
this.attendees = attendees;
this.absentees = absentees;
}
Expand Down

0 comments on commit 27ee2e5

Please sign in to comment.