Skip to content

Commit

Permalink
feat: 참가자 추가 - 기존 갱신과 생성 구분
Browse files Browse the repository at this point in the history
  • Loading branch information
SHEOMM committed Mar 31, 2024
1 parent 1f0036c commit 5f2fe3c
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public class Attendee {
private String note;

@Builder
public Attendee(Course course, String name, String note){
public Attendee(Long id, Course course, String name, String note){
this.id = id;
this.course = course;
this.name = name;
this.note = note;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.waruru.areyouhere.attendee.dto.request;

import com.waruru.areyouhere.attendee.service.dto.AttendeeData;
import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo;
import java.util.List;
import lombok.Data;

Expand All @@ -9,6 +10,6 @@
public class NewAttendeesRequestDto {
private Long courseId;

List<AttendeeData> newAttendees;
List<AttendeeInfo> newAttendees;
}

Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.waruru.areyouhere.attendee.service;

import com.waruru.areyouhere.attendee.service.dto.AttendeeData;
import com.waruru.areyouhere.attendee.service.dto.AttendeeDetailDto;
import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo;
import com.waruru.areyouhere.attendee.service.dto.ClassAttendees;
Expand All @@ -16,7 +15,7 @@ public interface AttendeeService {

public List<ClassAttendees> getClassAttendeesIfExistsOrEmpty(Long courseId);

public void createAll(Long courseId, List<AttendeeData> newAttendees);
public void createAll(Long courseId, List<AttendeeInfo> newAttendees);

public void deleteAll(List<Long> deleteAttendees);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import com.waruru.areyouhere.attendee.domain.repository.dto.AttendeeAttendDetailInfo;
import com.waruru.areyouhere.attendee.domain.repository.dto.ClassAttendeeInfo;
import com.waruru.areyouhere.attendee.domain.repository.dto.SessionAttendeeInfo;
import com.waruru.areyouhere.attendee.service.dto.AttendeeData;
import com.waruru.areyouhere.attendee.service.dto.AttendeeDetailDto;
import com.waruru.areyouhere.attendee.exception.ClassAttendeesEmptyException;
import com.waruru.areyouhere.attendee.exception.SessionAttendeesEmptyException;
import com.waruru.areyouhere.attendee.service.dto.AttendeeAttendanceInfo;
import com.waruru.areyouhere.attendee.service.dto.AttendeeInfo;
import com.waruru.areyouhere.attendee.service.dto.ClassAttendees;
import com.waruru.areyouhere.attendee.service.dto.DuplicateAttendees;
Expand Down Expand Up @@ -43,7 +41,7 @@ public class AttendeeServiceImpl implements AttendeeService{
private final AttendeeBatchRepository attendeeBatchRepository;
private final CourseRepository courseRepository;

public void createAll(Long courseId, List<AttendeeData> newAttendees){
public void createAll(Long courseId, List<AttendeeInfo> newAttendees){
Course course = courseRepository.findById(courseId)
.orElseThrow(CourseIdNotFoundException::new);

Expand All @@ -56,16 +54,28 @@ public void createAll(Long courseId, List<AttendeeData> newAttendees){
throw new AttendeesNotUniqueException("참여자 이름이 중복되었습니다.");
}

List<Attendee> attendeeToUpdate = new LinkedList<>();
List<Attendee> attendeesToSave = new LinkedList<>();

newAttendees.forEach(attendeeInfo -> {
if(attendeeInfo.getId() != null){
attendeeToUpdate.add(Attendee.builder()
.id(attendeeInfo.getId())
.course(course)
.name(attendeeInfo.getName())
.note(attendeeInfo.getNote())
.build());
}else{
attendeesToSave.add(Attendee.builder()
.course(course)
.name(attendeeInfo.getName())
.note(attendeeInfo.getNote())
.build());
}
});

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

attendeeBatchRepository.insertAttendeesBatch(attendees);
attendeeRepository.saveAll(attendeeToUpdate);
attendeeBatchRepository.insertAttendeesBatch(attendeesToSave);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ public void update(Long userId, String name, String password){
}

public void delete(Long userId){

managerRepository.deleteById(userId);
}
}

0 comments on commit 5f2fe3c

Please sign in to comment.