Skip to content

Commit

Permalink
feat: 출석 상태 update 리팩토링
Browse files Browse the repository at this point in the history
  • Loading branch information
SHEOMM committed Apr 1, 2024
1 parent e579293 commit ce81e6d
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.waruru.areyouhere.session.domain.repository.SessionRepository;
import com.waruru.areyouhere.session.exception.SessionIdNotFoundException;
import java.util.List;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
Expand Down Expand Up @@ -90,13 +91,17 @@ public void setAttend(Long sessionId, String attendanceName, Long attendeeId){
}

public void setAttendanceStatuses(Long sessionId , List<UpdateAttendance> updateAttendances){
List<Attendance> attendancesToUpdate = updateAttendances.stream()
.map(updateAttendance -> {
Attendance attendance = attendanceRepository.findById(updateAttendance.getAttendanceId())
.orElseThrow(SessionIdNotFoundException::new);
attendance.setAttended(updateAttendance.isAttendanceStatus());

for (UpdateAttendance updateAttendance : updateAttendances) {
Attendance attendance = attendanceRepository.findById(updateAttendance.getAttendanceId())
.orElseThrow(SessionIdNotFoundException::new);
attendance.setAttended(updateAttendance.isAttendanceStatus());
attendanceRepository.save(attendance);
}
return attendance;
})
.collect(Collectors.toList());

attendanceRepository.saveAll(attendancesToUpdate);
}

@Transactional(readOnly = true)
Expand Down

0 comments on commit ce81e6d

Please sign in to comment.