Skip to content

Commit

Permalink
feat: 추가 인원 배정 시 동명이인 검증 로직 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
SHEOMM committed Mar 26, 2024
1 parent 6a8a12a commit 9dd379d
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.waruru.areyouhere.course.domain.repository.CourseRepository;
import com.waruru.areyouhere.attendee.exception.AttendeesNotUniqueException;
import com.waruru.areyouhere.session.exception.CourseIdNotFoundException;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -46,17 +47,18 @@ public void createAttendees(Long courseId, List<AttendeeData> newAttendees){
attendeeData.getName() + (attendeeData.getNote() == null ? "" : attendeeData.getNote())
).toList();

if(!isAttendeesUnique(attendeeUniqueCheck)){
if(!isAttendeesUnique(attendeeUniqueCheck, courseId)){
throw new AttendeesNotUniqueException("참여자 이름이 중복되었습니다.");
}


List<Attendee> attendees = newAttendees.stream()
.map(newAttendee -> Attendee.builder()
.course(course)
.name(newAttendee.getName())
.note(newAttendee.getNote()).build())
.toList();
.course(course)
.name(newAttendee.getName())
.note(newAttendee.getNote())
.build())
.toList();

attendeeBatchRepository.insertAttendeesBatch(attendees);
}
Expand All @@ -78,6 +80,7 @@ public DuplicateAttendees getDuplicateAttendees(Long courseId, List<String> newA
})
.forEach(newAttendee -> duplicateAttendees.addDuplicateAttendee(null, newAttendee, null));


duplicated.forEach(newAttendee -> duplicateAttendees.addDuplicateAttendee(null, newAttendee, null));

getAlreadyExistsAttendees(courseId, newAttendees, duplicateAttendees);
Expand Down Expand Up @@ -159,9 +162,13 @@ public int getAttendeeByCourseId(Long courseId){
return attendeeRepository.findAttendeesByCourse_Id(courseId).size();
}

private boolean isAttendeesUnique(List<String> attendees) {
Set<String> uniqueAttendees = Set.copyOf(attendees);
return uniqueAttendees.size() == attendees.size();
private boolean isAttendeesUnique(List<String> attendees, Long courseId) {
Set<String> uniqueAttendees = new HashSet<>(Set.copyOf(attendees));
List<Attendee> attendeesByCourseId = attendeeRepository.findAttendeesByCourse_Id(courseId);
uniqueAttendees.addAll(attendeesByCourseId.stream().map(attendeeData ->
attendeeData.getName() + (attendeeData.getNote() == null ? "" : attendeeData.getNote())).toList());

return uniqueAttendees.size() == attendees.size() + attendeesByCourseId.size();
}


Expand Down

0 comments on commit 9dd379d

Please sign in to comment.