Skip to content

Commit

Permalink
feat(ScheduleService): 참가자 id와 약속의 uuid를 통해 자신의 스케줄 정보를 조회하는 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokmyungham committed Jul 26, 2024
1 parent a6ad004 commit 82b24c8
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,12 @@ public MomoApiResponse<ScheduleOneAttendeeResponse> findSchedulesOfAttendee(
ScheduleOneAttendeeResponse response = scheduleService.findSingleSchedule(uuid, attendeeName);
return new MomoApiResponse<>(response);
}

@GetMapping("/api/v1/meeting/{uuid}/my-schedule")
public MomoApiResponse<ScheduleOneAttendeeResponse> findMySchedule(
@PathVariable String uuid, @AuthAttendee long id
) {
ScheduleOneAttendeeResponse response = scheduleService.findMySchedule(uuid, id);
return new MomoApiResponse<>(response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,16 @@ public ScheduleOneAttendeeResponse findSingleSchedule(String uuid, String attend
List<Schedule> schedules = scheduleRepository.findAllByAttendee(attendee);
return ScheduleOneAttendeeResponse.of(attendee, ScheduleDateTimesResponse.from(schedules));
}

@Transactional(readOnly = true)
public ScheduleOneAttendeeResponse findMySchedule(String uuid, long attendeeId) {
Meeting meeting = meetingRepository.findByUuid(uuid)
.orElseThrow(() -> new MomoException(MeetingErrorCode.NOT_FOUND_MEETING));

Attendee attendee = attendeeRepository.findByIdAndMeeting(attendeeId, meeting)
.orElseThrow(() -> new MomoException(AttendeeErrorCode.NOT_FOUND_ATTENDEE));

List<Schedule> schedules = scheduleRepository.findAllByAttendee(attendee);
return ScheduleOneAttendeeResponse.of(attendee, ScheduleDateTimesResponse.from(schedules));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,10 @@ void create() {
.statusCode(HttpStatus.OK.value());
}


@DisplayName("약속 uuid와 참가자 이름으로 스케줄 조회를 요쳥하면 200 상태 코드를 응답한다.")
@Test
void findSchedulesOfAttendee() {
List<Schedule> schedules = new ArrayList<>();
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0300));
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0400));
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0500));
schedules.add(new Schedule(attendee, tomorrow, Timeslot.TIME_1600));
schedules.add(new Schedule(attendee, tomorrow, Timeslot.TIME_1700));
schedules.add(new Schedule(attendee, tomorrow, Timeslot.TIME_1300));
scheduleRepository.saveAll(schedules);
createAttendeeSchedule(attendee);

RestAssured.given().log().all()
.pathParam("uuid", meeting.getUuid())
Expand All @@ -124,4 +116,39 @@ void findAllSchedules() {
.then().log().all()
.statusCode(HttpStatus.OK.value());
}

@DisplayName("UUID와 참가자 ID로 자신의 스케줄을 조회한다.")
@Test
void findMySchedule() {
AttendeeLoginRequest loginRequest = new AttendeeLoginRequest(attendee.name(), attendee.password());

createAttendeeSchedule(attendee);

String token = RestAssured.given().log().all()
.contentType(ContentType.JSON)
.body(loginRequest)
.when().post("/api/v1/login/{uuid}", meeting.getUuid())
.then().log().all()
.statusCode(HttpStatus.OK.value())
.extract().jsonPath().getString("data.token");

RestAssured.given().log().all()
.header("Authorization", "Bearer " + token)
.pathParam("uuid", meeting.getUuid())
.contentType(ContentType.JSON)
.when().get("/api/v1/meeting/{uuid}/my-schedule")
.then().log().all()
.statusCode(HttpStatus.OK.value());
}

private void createAttendeeSchedule(Attendee attendee) {
List<Schedule> schedules = new ArrayList<>();
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0300));
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0400));
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0500));
schedules.add(new Schedule(attendee, tomorrow, Timeslot.TIME_1600));
schedules.add(new Schedule(attendee, tomorrow, Timeslot.TIME_1700));
schedules.add(new Schedule(attendee, tomorrow, Timeslot.TIME_1300));
scheduleRepository.saveAll(schedules);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void findAllSchedulesInMeetingByUuid() {
@DisplayName("참가자 이름과 약속 UUID로 스케줄을 조회한다.")
@Test
void findSingleSchedule() {
setOneAttendeeSchedule();
createAttendeeSchedule(attendee);

ScheduleOneAttendeeResponse result = scheduleService.findSingleSchedule(meeting.getUuid(), attendee.name());
ScheduleDateTimesResponse firstTimeResponse = result.schedules().get(0);
Expand All @@ -169,7 +169,7 @@ void findSingleSchedule() {
@DisplayName("참가자 스케줄시 약속이 존재하지 않으면 예외가 발생한다.")
@Test
void throwsIfNoAppointmentInParticipantSchedule() {
setOneAttendeeSchedule();
createAttendeeSchedule(attendee);
String givenUUID = "1234";
String name = attendee.name();

Expand All @@ -181,7 +181,7 @@ void throwsIfNoAppointmentInParticipantSchedule() {
@DisplayName("참가자 스케줄시 참가자가 존재하지 않으면 예외가 발생한다.")
@Test
void throwsIfNoAttendeeInParticipantSchedule() {
setOneAttendeeSchedule();
createAttendeeSchedule(attendee);
String uuid = meeting.getUuid();
String givenAttendeeName = "NOTHING";

Expand All @@ -190,7 +190,22 @@ void throwsIfNoAttendeeInParticipantSchedule() {
.hasMessage(AttendeeErrorCode.NOT_FOUND_ATTENDEE.message());
}

private void setOneAttendeeSchedule() {
@DisplayName("UUID와 참가자 ID로 자신의 스케줄을 조회한다.")
@Test
void findMySchedule() {
createAttendeeSchedule(attendee);

ScheduleOneAttendeeResponse result = scheduleService.findMySchedule(meeting.getUuid(), attendee.getId());
ScheduleDateTimesResponse firstTimeResponse = result.schedules().get(0);

assertAll(
() -> assertThat(result.attendeeName()).isEqualTo(attendee.name()),
() -> assertThat(result.schedules()).hasSize(2),
() -> assertThat(firstTimeResponse.times()).hasSize(3)
);
}

private void createAttendeeSchedule(Attendee attendee) {
List<Schedule> schedules = new ArrayList<>();
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0300));
schedules.add(new Schedule(attendee, today, Timeslot.TIME_0400));
Expand Down

0 comments on commit 82b24c8

Please sign in to comment.