From 7c1da61284d52e2f2bcd09ba3375e53190008529 Mon Sep 17 00:00:00 2001 From: Seokmyung Ham Date: Fri, 26 Jul 2024 12:17:32 +0900 Subject: [PATCH] =?UTF-8?q?feat(ScheduleService):=20=EC=B0=B8=EA=B0=80?= =?UTF-8?q?=EC=9E=90=20id=EC=99=80=20=EC=95=BD=EC=86=8D=EC=9D=98=20uuid?= =?UTF-8?q?=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EC=9E=90=EC=8B=A0=EC=9D=98=20?= =?UTF-8?q?=EC=8A=A4=EC=BC=80=EC=A4=84=20=EC=A0=95=EB=B3=B4=EB=A5=BC=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=ED=95=98=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../schedule/ScheduleController.java | 8 ++++ .../service/schedule/ScheduleService.java | 12 +++++ .../schedule/ScheduleControllerTest.java | 45 +++++++++++++++---- .../service/schedule/ScheduleServiceTest.java | 23 ++++++++-- 4 files changed, 75 insertions(+), 13 deletions(-) diff --git a/backend/src/main/java/com/woowacourse/momo/controller/schedule/ScheduleController.java b/backend/src/main/java/com/woowacourse/momo/controller/schedule/ScheduleController.java index 588186646..c2f43a0bc 100644 --- a/backend/src/main/java/com/woowacourse/momo/controller/schedule/ScheduleController.java +++ b/backend/src/main/java/com/woowacourse/momo/controller/schedule/ScheduleController.java @@ -40,4 +40,12 @@ public MomoApiResponse findSchedulesOfAttendee( ScheduleOneAttendeeResponse response = scheduleService.findSingleSchedule(uuid, attendeeName); return new MomoApiResponse<>(response); } + + @GetMapping("/api/v1/meeting/{uuid}/my-schedule") + public MomoApiResponse findMySchedule( + @PathVariable String uuid, @AuthAttendee long id + ) { + ScheduleOneAttendeeResponse response = scheduleService.findMySchedule(uuid, id); + return new MomoApiResponse<>(response); + } } diff --git a/backend/src/main/java/com/woowacourse/momo/service/schedule/ScheduleService.java b/backend/src/main/java/com/woowacourse/momo/service/schedule/ScheduleService.java index e45853bfa..6728a5058 100644 --- a/backend/src/main/java/com/woowacourse/momo/service/schedule/ScheduleService.java +++ b/backend/src/main/java/com/woowacourse/momo/service/schedule/ScheduleService.java @@ -88,4 +88,16 @@ public ScheduleOneAttendeeResponse findSingleSchedule(String uuid, String attend List 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 schedules = scheduleRepository.findAllByAttendee(attendee); + return ScheduleOneAttendeeResponse.of(attendee, ScheduleDateTimesResponse.from(schedules)); + } } diff --git a/backend/src/test/java/com/woowacourse/momo/controller/schedule/ScheduleControllerTest.java b/backend/src/test/java/com/woowacourse/momo/controller/schedule/ScheduleControllerTest.java index c4c89b0c8..8d37e8894 100644 --- a/backend/src/test/java/com/woowacourse/momo/controller/schedule/ScheduleControllerTest.java +++ b/backend/src/test/java/com/woowacourse/momo/controller/schedule/ScheduleControllerTest.java @@ -94,18 +94,10 @@ void create() { .statusCode(HttpStatus.OK.value()); } - @DisplayName("약속 uuid와 참가자 이름으로 스케줄 조회를 요쳥하면 200 상태 코드를 응답한다.") @Test void findSchedulesOfAttendee() { - List 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()) @@ -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 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); + } } diff --git a/backend/src/test/java/com/woowacourse/momo/service/schedule/ScheduleServiceTest.java b/backend/src/test/java/com/woowacourse/momo/service/schedule/ScheduleServiceTest.java index 6d8bd7d18..f996c9be8 100644 --- a/backend/src/test/java/com/woowacourse/momo/service/schedule/ScheduleServiceTest.java +++ b/backend/src/test/java/com/woowacourse/momo/service/schedule/ScheduleServiceTest.java @@ -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); @@ -169,7 +169,7 @@ void findSingleSchedule() { @DisplayName("참가자 스케줄시 약속이 존재하지 않으면 예외가 발생한다.") @Test void throwsIfNoAppointmentInParticipantSchedule() { - setOneAttendeeSchedule(); + createAttendeeSchedule(attendee); String givenUUID = "1234"; String name = attendee.name(); @@ -181,7 +181,7 @@ void throwsIfNoAppointmentInParticipantSchedule() { @DisplayName("참가자 스케줄시 참가자가 존재하지 않으면 예외가 발생한다.") @Test void throwsIfNoAttendeeInParticipantSchedule() { - setOneAttendeeSchedule(); + createAttendeeSchedule(attendee); String uuid = meeting.getUuid(); String givenAttendeeName = "NOTHING"; @@ -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 schedules = new ArrayList<>(); schedules.add(new Schedule(attendee, today, Timeslot.TIME_0300)); schedules.add(new Schedule(attendee, today, Timeslot.TIME_0400));