From 5f2fe3c0467e127e2f0bdd8ccde3160efc7b0309 Mon Sep 17 00:00:00 2001 From: SHEOMM Date: Sun, 31 Mar 2024 16:07:03 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=B0=B8=EA=B0=80=EC=9E=90=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80=20-=20=EA=B8=B0=EC=A1=B4=20=EA=B0=B1=EC=8B=A0?= =?UTF-8?q?=EA=B3=BC=20=EC=83=9D=EC=84=B1=20=EA=B5=AC=EB=B6=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../attendee/domain/entity/Attendee.java | 3 +- .../dto/request/NewAttendeesRequestDto.java | 3 +- .../attendee/service/AttendeeService.java | 3 +- .../attendee/service/AttendeeServiceImpl.java | 34 ++++++++++++------- .../service/SessionManagerService.java | 1 + 5 files changed, 28 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/waruru/areyouhere/attendee/domain/entity/Attendee.java b/src/main/java/com/waruru/areyouhere/attendee/domain/entity/Attendee.java index 0c88725..b242f40 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/domain/entity/Attendee.java +++ b/src/main/java/com/waruru/areyouhere/attendee/domain/entity/Attendee.java @@ -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; diff --git a/src/main/java/com/waruru/areyouhere/attendee/dto/request/NewAttendeesRequestDto.java b/src/main/java/com/waruru/areyouhere/attendee/dto/request/NewAttendeesRequestDto.java index 1035d60..8f2902f 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/dto/request/NewAttendeesRequestDto.java +++ b/src/main/java/com/waruru/areyouhere/attendee/dto/request/NewAttendeesRequestDto.java @@ -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; @@ -9,6 +10,6 @@ public class NewAttendeesRequestDto { private Long courseId; - List newAttendees; + List newAttendees; } diff --git a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java index 2a7767d..4fdd27c 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java +++ b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeService.java @@ -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; @@ -16,7 +15,7 @@ public interface AttendeeService { public List getClassAttendeesIfExistsOrEmpty(Long courseId); - public void createAll(Long courseId, List newAttendees); + public void createAll(Long courseId, List newAttendees); public void deleteAll(List deleteAttendees); diff --git a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java index bb48d38..b3d85e8 100644 --- a/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java +++ b/src/main/java/com/waruru/areyouhere/attendee/service/AttendeeServiceImpl.java @@ -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; @@ -43,7 +41,7 @@ public class AttendeeServiceImpl implements AttendeeService{ private final AttendeeBatchRepository attendeeBatchRepository; private final CourseRepository courseRepository; - public void createAll(Long courseId, List newAttendees){ + public void createAll(Long courseId, List newAttendees){ Course course = courseRepository.findById(courseId) .orElseThrow(CourseIdNotFoundException::new); @@ -56,16 +54,28 @@ public void createAll(Long courseId, List newAttendees){ throw new AttendeesNotUniqueException("참여자 이름이 중복되었습니다."); } + List attendeeToUpdate = new LinkedList<>(); + List 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 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 diff --git a/src/main/java/com/waruru/areyouhere/manager/service/SessionManagerService.java b/src/main/java/com/waruru/areyouhere/manager/service/SessionManagerService.java index a22a40f..11c8e84 100644 --- a/src/main/java/com/waruru/areyouhere/manager/service/SessionManagerService.java +++ b/src/main/java/com/waruru/areyouhere/manager/service/SessionManagerService.java @@ -86,6 +86,7 @@ public void update(Long userId, String name, String password){ } public void delete(Long userId){ + managerRepository.deleteById(userId); } }