Skip to content

Commit

Permalink
[BE] 약속 입장 조회 로직 추가 (#390)
Browse files Browse the repository at this point in the history
* feat(MeetingController): 약속 입장 정보 조회 컨트롤러 추가

* style(MeetingHomeResponse): 약속 입장 조회 레코드명 수정

* refactor: 불명확한 `@DisplayName` 수정

* refactor: 불명확한 메서드명 수정

* feat: Controller Swagger 문서화 추가
  • Loading branch information
ikjo39 authored Oct 11, 2024
1 parent 875ccc8 commit dd6740f
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import kr.momo.service.meeting.MeetingConfirmService;
import kr.momo.service.meeting.MeetingService;
import kr.momo.service.meeting.dto.ConfirmedMeetingResponse;
import kr.momo.service.meeting.dto.MeetingHomeResponse;
import kr.momo.service.meeting.dto.MeetingConfirmRequest;
import kr.momo.service.meeting.dto.MeetingConfirmResponse;
import kr.momo.service.meeting.dto.MeetingCreateRequest;
Expand Down Expand Up @@ -73,6 +74,12 @@ public MomoApiResponse<ConfirmedMeetingResponse> findConfirmedMeeting(@PathVaria
return new MomoApiResponse<>(response);
}

@GetMapping("/api/v1/meetings/{uuid}/home")
public MomoApiResponse<MeetingHomeResponse> findMeetingHome(@PathVariable String uuid) {
MeetingHomeResponse response = meetingService.findMeetingHome(uuid);
return new MomoApiResponse<>(response);
}

@PatchMapping("/api/v1/meetings/{uuid}/lock")
public void lock(@PathVariable String uuid, @AuthAttendee long id) {
meetingService.lock(uuid, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import kr.momo.service.meeting.dto.MeetingConfirmResponse;
import kr.momo.service.meeting.dto.MeetingCreateRequest;
import kr.momo.service.meeting.dto.MeetingCreateResponse;
import kr.momo.service.meeting.dto.MeetingHomeResponse;
import kr.momo.service.meeting.dto.MeetingResponse;
import kr.momo.service.meeting.dto.MeetingSharingResponse;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -147,4 +148,11 @@ ResponseEntity<Void> cancelConfirmedMeeting(
@PathVariable @Schema(description = "약속 UUID") String uuid,
@AuthAttendee @Schema(hidden = true) long id
);

@Operation(summary = "약속 입장 정보 조회", description = "약속 입장에 필요한 정보를 조회하는 API 입니다.")
@ApiSuccessResponse.NoContent("약속 입장 정보 조회 성공")
@ApiErrorResponse.BadRequest(ERROR_CODE_TABLE_HEADER + """
| NOT_FOUND_MEETING | 존재하지 않는 약속 정보 입니다. |
""")
MomoApiResponse<MeetingHomeResponse> findMeetingHome(@PathVariable @Schema(description = "약속 UUID") String uuid);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import kr.momo.exception.code.AttendeeErrorCode;
import kr.momo.exception.code.MeetingErrorCode;
import kr.momo.service.auth.JwtManager;
import kr.momo.service.meeting.dto.MeetingHomeResponse;
import kr.momo.service.meeting.dto.MeetingCreateRequest;
import kr.momo.service.meeting.dto.MeetingCreateResponse;
import kr.momo.service.meeting.dto.MeetingResponse;
Expand Down Expand Up @@ -110,6 +111,13 @@ public MeetingSharingResponse findMeetingSharing(String uuid) {
return MeetingSharingResponse.from(meeting);
}

@Transactional(readOnly = true)
public MeetingHomeResponse findMeetingHome(String uuid) {
Meeting meeting = meetingRepository.findByUuid(uuid)
.orElseThrow(() -> new MomoException(MeetingErrorCode.NOT_FOUND_MEETING));
return MeetingHomeResponse.from(meeting);
}

@Transactional
public void lock(String uuid, long id) {
Meeting meeting = meetingRepository.findByUuid(uuid)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package kr.momo.service.meeting.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import kr.momo.domain.meeting.Meeting;

@Schema(description = "약속 입장 응답")
public record MeetingHomeResponse(

@Schema(description = "약속 이름")
String meetingName,

@Schema(description = "약속 유형")
String type
) {
public static MeetingHomeResponse from(Meeting meeting) {
return new MeetingHomeResponse(meeting.getName(), meeting.getType().name());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -689,4 +689,18 @@ private MeetingConfirmRequest getValidFindRequest(AvailableDate tomorrow) {
Timeslot.TIME_0600.startTime()
);
}

@DisplayName("약속 입장 정보를 조회하면 200 상태 코드를 응답한다.")
@Test
void findMeetingHome() {
Meeting meeting = MeetingFixture.MOVIE.create();
meeting = meetingRepository.save(meeting);

RestAssured.given().log().all()
.pathParam("uuid", meeting.getUuid())
.contentType(ContentType.JSON)
.when().get("/api/v1/meetings/{uuid}/home")
.then().log().all()
.statusCode(HttpStatus.OK.value());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.LocalTime;
import java.time.ZoneId;
import java.util.List;
import java.util.UUID;
import kr.momo.domain.attendee.Attendee;
import kr.momo.domain.attendee.AttendeeRepository;
import kr.momo.domain.availabledate.AvailableDate;
Expand All @@ -24,6 +25,7 @@
import kr.momo.exception.code.MeetingErrorCode;
import kr.momo.fixture.AttendeeFixture;
import kr.momo.fixture.MeetingFixture;
import kr.momo.service.meeting.dto.MeetingHomeResponse;
import kr.momo.service.meeting.dto.MeetingCreateRequest;
import kr.momo.service.meeting.dto.MeetingResponse;
import kr.momo.service.meeting.dto.MeetingSharingResponse;
Expand Down Expand Up @@ -258,4 +260,28 @@ void throwsExceptionWhenUnlockAttendeeGuest() {
.isInstanceOf(MomoException.class)
.hasMessage(AttendeeErrorCode.ACCESS_DENIED.message());
}

@DisplayName("UUID로 약속 입장 정보를 조회한다.")
@Test
void findMeetingHome() {
Meeting meeting = meetingRepository.save(MeetingFixture.GAME.create());
String uuid = meeting.getUuid();

MeetingHomeResponse result = meetingService.findMeetingHome(uuid);

assertAll(
() -> assertThat(result.meetingName()).isEqualTo(meeting.getName()),
() -> assertThat(result.type()).isEqualTo(meeting.getType().name())
);
}

@DisplayName("약속 입장 정보를 조회시 UUID가 존재하지 않으면 예외가 발생한다.")
@Test
void throwsExceptionWhenFindHomeNoMeeting() {
String uuid = UUID.randomUUID().toString();

assertThatThrownBy(() -> meetingService.findMeetingHome(uuid))
.isInstanceOf(MomoException.class)
.hasMessage(MeetingErrorCode.NOT_FOUND_MEETING.message());
}
}

0 comments on commit dd6740f

Please sign in to comment.