From 070b193de977a5e762de14027fe08798bc863ad6 Mon Sep 17 00:00:00 2001 From: Seokmyung Ham Date: Thu, 25 Jul 2024 22:01:59 +0900 Subject: [PATCH] =?UTF-8?q?[BE]=20=EA=B8=B0=EC=A1=B4=20=EC=95=BD=EC=86=8D?= =?UTF-8?q?=20=EC=A0=95=EB=B3=B4=20=EC=A1=B0=ED=9A=8C=20API=20=EC=9D=91?= =?UTF-8?q?=EB=8B=B5=EC=97=90=20=EC=B0=B8=EA=B0=80=EC=9E=90=EB=93=A4?= =?UTF-8?q?=EC=9D=98=20=EC=A0=95=EB=B3=B4=20=EC=B6=94=EA=B0=80=20(#81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit feat(MeetingService): 기존 약속 정보 조회 API 응답에 참가자들 정보 추가 --- .../momo/domain/attendee/AttendeeRepository.java | 3 +++ .../momo/service/meeting/MeetingService.java | 3 ++- .../momo/service/meeting/dto/MeetingResponse.java | 13 ++++++++++--- .../controller/meeting/MeetingControllerTest.java | 10 ++++++++++ .../momo/service/meeting/MeetingServiceTest.java | 3 +++ 5 files changed, 28 insertions(+), 4 deletions(-) diff --git a/backend/src/main/java/com/woowacourse/momo/domain/attendee/AttendeeRepository.java b/backend/src/main/java/com/woowacourse/momo/domain/attendee/AttendeeRepository.java index 1e217cf28..fe6a4a8f2 100644 --- a/backend/src/main/java/com/woowacourse/momo/domain/attendee/AttendeeRepository.java +++ b/backend/src/main/java/com/woowacourse/momo/domain/attendee/AttendeeRepository.java @@ -1,10 +1,13 @@ package com.woowacourse.momo.domain.attendee; import com.woowacourse.momo.domain.meeting.Meeting; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; public interface AttendeeRepository extends JpaRepository { Optional findByMeetingAndName(Meeting meeting, AttendeeName name); + + List findAllByMeeting(Meeting meeting); } 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 0cd249945..c5650f50e 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 @@ -56,8 +56,9 @@ public MeetingResponse findByUUID(String uuid) { Meeting meeting = meetingRepository.findByUuid(uuid) .orElseThrow(() -> new MomoException(MeetingErrorCode.NOT_FOUND_MEETING)); AvailableDates availableDates = new AvailableDates(availableDateRepository.findAllByMeeting(meeting)); + List attendees = attendeeRepository.findAllByMeeting(meeting); - return MeetingResponse.from(meeting, availableDates); + return MeetingResponse.of(meeting, availableDates, attendees); } @Transactional(readOnly = true) diff --git a/backend/src/main/java/com/woowacourse/momo/service/meeting/dto/MeetingResponse.java b/backend/src/main/java/com/woowacourse/momo/service/meeting/dto/MeetingResponse.java index b73ffae72..784ae2eb0 100644 --- a/backend/src/main/java/com/woowacourse/momo/service/meeting/dto/MeetingResponse.java +++ b/backend/src/main/java/com/woowacourse/momo/service/meeting/dto/MeetingResponse.java @@ -2,6 +2,7 @@ import com.fasterxml.jackson.annotation.JsonFormat; import com.fasterxml.jackson.annotation.JsonFormat.Shape; +import com.woowacourse.momo.domain.attendee.Attendee; import com.woowacourse.momo.domain.availabledate.AvailableDate; import com.woowacourse.momo.domain.availabledate.AvailableDates; import com.woowacourse.momo.domain.meeting.Meeting; @@ -14,19 +15,25 @@ public record MeetingResponse( String meetingName, @JsonFormat(shape = Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") LocalTime firstTime, @JsonFormat(shape = Shape.STRING, pattern = "HH:mm", timezone = "Asia/Seoul") LocalTime lastTime, - List availableDates + List availableDates, + List attendeeNames ) { - public static MeetingResponse from(Meeting meeting, AvailableDates availableDates) { + public static MeetingResponse of(Meeting meeting, AvailableDates availableDates, List attendees) { List dates = availableDates.getAvailableDates().stream() .map(AvailableDate::getDate) .collect(Collectors.toList()); + List attendeeNames = attendees.stream() + .map(Attendee::name) + .toList(); + return new MeetingResponse( meeting.getName(), meeting.startTimeslotTime(), meeting.endTimeslotTime(), - dates + dates, + attendeeNames ); } } diff --git a/backend/src/test/java/com/woowacourse/momo/controller/meeting/MeetingControllerTest.java b/backend/src/test/java/com/woowacourse/momo/controller/meeting/MeetingControllerTest.java index 717166b99..da1fc3d3a 100644 --- a/backend/src/test/java/com/woowacourse/momo/controller/meeting/MeetingControllerTest.java +++ b/backend/src/test/java/com/woowacourse/momo/controller/meeting/MeetingControllerTest.java @@ -3,10 +3,13 @@ import static org.assertj.core.api.SoftAssertions.assertSoftly; import static org.hamcrest.Matchers.containsString; +import com.woowacourse.momo.domain.attendee.Attendee; +import com.woowacourse.momo.domain.attendee.AttendeeRepository; import com.woowacourse.momo.domain.availabledate.AvailableDate; import com.woowacourse.momo.domain.availabledate.AvailableDateRepository; import com.woowacourse.momo.domain.meeting.Meeting; import com.woowacourse.momo.domain.meeting.MeetingRepository; +import com.woowacourse.momo.fixture.AttendeeFixture; import com.woowacourse.momo.fixture.MeetingFixture; import com.woowacourse.momo.service.meeting.dto.MeetingCreateRequest; import com.woowacourse.momo.support.IsolateDatabase; @@ -36,6 +39,9 @@ class MeetingControllerTest { @Autowired private MeetingRepository meetingRepository; + @Autowired + private AttendeeRepository attendeeRepository; + @Autowired private AvailableDateRepository availableDateRepository; @@ -48,9 +54,11 @@ void setUp() { @Test void find() { Meeting meeting = meetingRepository.save(MeetingFixture.DINNER.create()); + Attendee attendee = attendeeRepository.save(AttendeeFixture.HOST_JAZZ.create(meeting)); AvailableDate today = availableDateRepository.save(new AvailableDate(LocalDate.now(), meeting)); AvailableDate tomorrow = availableDateRepository.save(new AvailableDate(LocalDate.now().plusDays(1), meeting)); List dates = List.of(today.getDate().toString(), tomorrow.getDate().toString()); + List attendeeNames = List.of(attendee.name()); Response response = RestAssured.given().log().all() .contentType(ContentType.JSON) @@ -60,6 +68,7 @@ void find() { String firstTime = response.jsonPath().getString("data.firstTime"); String lastTime = response.jsonPath().getString("data.lastTime"); List availableDatesList = response.jsonPath().getList("data.availableDates", String.class); + List attendeeNamesList = response.jsonPath().getList("data.attendeeNames", String.class); assertSoftly(softAssertions -> { softAssertions.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value()); @@ -67,6 +76,7 @@ void find() { softAssertions.assertThat(firstTime).isEqualTo(meeting.startTimeslotTime().toString()); softAssertions.assertThat(lastTime).isEqualTo(meeting.endTimeslotTime().toString()); softAssertions.assertThat(availableDatesList).containsExactlyElementsOf(dates); + softAssertions.assertThat(attendeeNamesList).containsExactlyElementsOf(attendeeNames); }); } diff --git a/backend/src/test/java/com/woowacourse/momo/service/meeting/MeetingServiceTest.java b/backend/src/test/java/com/woowacourse/momo/service/meeting/MeetingServiceTest.java index 46283109f..33140d5a4 100644 --- a/backend/src/test/java/com/woowacourse/momo/service/meeting/MeetingServiceTest.java +++ b/backend/src/test/java/com/woowacourse/momo/service/meeting/MeetingServiceTest.java @@ -4,6 +4,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.assertj.core.api.SoftAssertions.assertSoftly; +import com.woowacourse.momo.domain.attendee.Attendee; import com.woowacourse.momo.domain.attendee.AttendeeRepository; import com.woowacourse.momo.domain.availabledate.AvailableDate; import com.woowacourse.momo.domain.availabledate.AvailableDateRepository; @@ -47,6 +48,7 @@ class MeetingServiceTest { @Test void findByUUID() { Meeting meeting = meetingRepository.save(MeetingFixture.MOVIE.create()); + Attendee attendee = attendeeRepository.save(AttendeeFixture.HOST_JAZZ.create(meeting)); List availableDates = List.of( availableDateRepository.save(new AvailableDate(LocalDate.now(), meeting)), availableDateRepository.save(new AvailableDate(LocalDate.now().plusDays(1), meeting)) @@ -59,6 +61,7 @@ void findByUUID() { softAssertions.assertThat(response.lastTime()).isEqualTo(meeting.endTimeslotTime()); softAssertions.assertThat(response.meetingName()).isEqualTo(meeting.getName()); softAssertions.assertThat(response.availableDates().size()).isEqualTo(availableDates.size()); + softAssertions.assertThat(response.attendeeNames()).isEqualTo(List.of(attendee.name())); }); }