Skip to content

Commit

Permalink
feat(MeetingService): 기존 약속 정보 조회 API 응답에 참가자들 정보 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokmyungham committed Jul 25, 2024
1 parent 4c8ddfa commit 89c978b
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -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<Attendee, Long> {

Optional<Attendee> findByMeetingAndName(Meeting meeting, AttendeeName name);

List<Attendee> findAllByMeeting(Meeting meeting);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<Attendee> attendees = attendeeRepository.findAllByMeeting(meeting);

return MeetingResponse.from(meeting, availableDates);
return MeetingResponse.of(meeting, availableDates, attendees);
}

@Transactional(readOnly = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<LocalDate> availableDates
List<LocalDate> availableDates,
List<String> attendeeNames
) {

public static MeetingResponse from(Meeting meeting, AvailableDates availableDates) {
public static MeetingResponse of(Meeting meeting, AvailableDates availableDates, List<Attendee> attendees) {
List<LocalDate> dates = availableDates.getAvailableDates().stream()
.map(AvailableDate::getDate)
.collect(Collectors.toList());

List<String> attendeeNames = attendees.stream()
.map(Attendee::name)
.toList();

return new MeetingResponse(
meeting.getName(),
meeting.startTimeslotTime(),
meeting.endTimeslotTime(),
dates
dates,
attendeeNames
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -36,6 +39,9 @@ class MeetingControllerTest {
@Autowired
private MeetingRepository meetingRepository;

@Autowired
private AttendeeRepository attendeeRepository;

@Autowired
private AvailableDateRepository availableDateRepository;

Expand All @@ -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<String> dates = List.of(today.getDate().toString(), tomorrow.getDate().toString());
List<String> attendeeNames = List.of(attendee.name());

Response response = RestAssured.given().log().all()
.contentType(ContentType.JSON)
Expand All @@ -60,13 +68,15 @@ void find() {
String firstTime = response.jsonPath().getString("data.firstTime");
String lastTime = response.jsonPath().getString("data.lastTime");
List<String> availableDatesList = response.jsonPath().getList("data.availableDates", String.class);
List<String> attendeeNamesList = response.jsonPath().getList("data.attendeeNames", String.class);

assertSoftly(softAssertions -> {
softAssertions.assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
softAssertions.assertThat(meetingName).isEqualTo(meeting.getName());
softAssertions.assertThat(firstTime).isEqualTo(meeting.startTimeslotTime().toString());
softAssertions.assertThat(lastTime).isEqualTo(meeting.endTimeslotTime().toString());
softAssertions.assertThat(availableDatesList).containsExactlyElementsOf(dates);
softAssertions.assertThat(attendeeNamesList).containsExactlyElementsOf(attendeeNames);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<AvailableDate> availableDates = List.of(
availableDateRepository.save(new AvailableDate(LocalDate.now(), meeting)),
availableDateRepository.save(new AvailableDate(LocalDate.now().plusDays(1), meeting))
Expand All @@ -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()));
});
}

Expand Down

0 comments on commit 89c978b

Please sign in to comment.