From fb068f908941177ec1f78c132d76ce0e4d56f71e Mon Sep 17 00:00:00 2001 From: Eunhee Baek <78892355+ehBeak@users.noreply.github.com> Date: Wed, 24 Jul 2024 18:31:01 +0900 Subject: [PATCH] =?UTF-8?q?refactor(MeetingService):=20create=20=ED=95=A8?= =?UTF-8?q?=EC=88=98=20private=20=EB=A9=94=EC=84=9C=EB=93=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../momo/service/meeting/MeetingService.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/backend/src/main/java/com/woowacourse/momo/service/meeting/MeetingService.java b/backend/src/main/java/com/woowacourse/momo/service/meeting/MeetingService.java index 2c2916564..034bf917d 100644 --- a/backend/src/main/java/com/woowacourse/momo/service/meeting/MeetingService.java +++ b/backend/src/main/java/com/woowacourse/momo/service/meeting/MeetingService.java @@ -17,6 +17,7 @@ import com.woowacourse.momo.service.meeting.dto.MeetingSharingResponse; import com.woowacourse.momo.service.schedule.dto.ScheduleTimeResponse; import java.time.LocalDate; +import java.time.LocalTime; import java.util.Comparator; import java.util.List; import java.util.Map; @@ -60,21 +61,25 @@ public MeetingResponse findByUUID(String uuid) { @Transactional public String create(MeetingCreateRequest request) { - String uuid = UUID.randomUUID().toString(); - Meeting meeting = new Meeting( - request.meetingName(), - uuid, - request.meetingStartTime(), - request.meetingEndTime() - ); - Meeting savedMeeting = meetingRepository.save(meeting); + Meeting meeting = saveMeeting(request.meetingName(), request.meetingStartTime(), request.meetingEndTime()); + saveAvailableDates(request.meetingAvailableDates(), meeting); + saveAttendee(meeting, request.hostName(), request.hostPassword(), Role.HOST); + return meeting.getUuid(); + } + + private Meeting saveMeeting(String meetingName, LocalTime startTime, LocalTime endTime) { + Meeting meeting = new Meeting(meetingName, UUID.randomUUID().toString(), startTime, endTime); + return meetingRepository.save(meeting); + } - AvailableDates availableDates = new AvailableDates(request.meetingAvailableDates(), meeting); + private void saveAvailableDates(List dates, Meeting meeting) { + AvailableDates availableDates = new AvailableDates(dates, meeting); availableDateRepository.saveAll(availableDates.getDates()); + } - Attendee attendee = new Attendee(savedMeeting, request.hostName(), request.hostPassword(), Role.HOST); + private void saveAttendee(Meeting meeting, String hostName, String hostPassword, Role role) { + Attendee attendee = new Attendee(meeting, hostName, hostPassword, role); attendeeRepository.save(attendee); - return uuid; } public MeetingSharingResponse findMeetingSharing(String uuid) {