From 6f9f2d4303f8ac230aa4b2aca071ae12dc9d6057 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:15:30 +0900 Subject: [PATCH 1/2] =?UTF-8?q?[feat]=20Redis=20=EC=BA=90=EC=8B=B1=20?= =?UTF-8?q?=EC=98=A4=EB=A5=98=EB=A5=BC=20=EB=A7=89=EA=B8=B0=20=EC=9C=84?= =?UTF-8?q?=ED=95=B4,=20Wrapper=20=EB=A0=88=EC=BD=94=EB=93=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/WrapAccommodationResponse.java | 11 ++++++++++ .../dto/response/WrapRoomResponse.java | 11 ++++++++++ .../service/AccomodationService.java | 20 +++++++++++-------- 3 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapAccommodationResponse.java create mode 100644 src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapRoomResponse.java diff --git a/src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapAccommodationResponse.java b/src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapAccommodationResponse.java new file mode 100644 index 00000000..309fc5c2 --- /dev/null +++ b/src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapAccommodationResponse.java @@ -0,0 +1,11 @@ +package com.coolpeace.domain.accommodation.dto.response; + +import java.util.List; + +public record WrapAccommodationResponse( + List accommodationResponses +) { + public static WrapAccommodationResponse from(List accommodationResponses) { + return new WrapAccommodationResponse(accommodationResponses); + } +} diff --git a/src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapRoomResponse.java b/src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapRoomResponse.java new file mode 100644 index 00000000..29e5952a --- /dev/null +++ b/src/main/java/com/coolpeace/domain/accommodation/dto/response/WrapRoomResponse.java @@ -0,0 +1,11 @@ +package com.coolpeace.domain.accommodation.dto.response; + +import java.util.List; + +public record WrapRoomResponse( + List roomResponses +) { + public static WrapRoomResponse from(List roomResponses) { + return new WrapRoomResponse(roomResponses); + } +} diff --git a/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java b/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java index 1d437910..dfbe351c 100644 --- a/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java +++ b/src/main/java/com/coolpeace/domain/accommodation/service/AccomodationService.java @@ -2,6 +2,8 @@ import com.coolpeace.domain.accommodation.dto.response.AccommodationResponse; import com.coolpeace.domain.accommodation.dto.response.RoomResponse; +import com.coolpeace.domain.accommodation.dto.response.WrapAccommodationResponse; +import com.coolpeace.domain.accommodation.dto.response.WrapRoomResponse; import com.coolpeace.domain.accommodation.entity.Accommodation; import com.coolpeace.domain.accommodation.exception.AccommodationNotFoundException; import com.coolpeace.domain.accommodation.repository.AccommodationRepository; @@ -24,20 +26,21 @@ public class AccomodationService { private final RoomRepository roomRepository; @Cacheable(value = "accommodation", key = "#jwtPrincipal.toString()",cacheManager = "contentCacheManager") - public List getAccommodations(JwtPrincipal jwtPrincipal) { + public WrapAccommodationResponse getAccommodations(JwtPrincipal jwtPrincipal) { Long memberId = Long.parseLong(jwtPrincipal.getMemberId()); Member member = memberRepository.findById(memberId) .orElseThrow(MemberNotFoundException::new); - return accommodationRepository.findAllByMember(member) - .stream() - .map(AccommodationResponse::fromEntity) - .toList(); + return WrapAccommodationResponse + .from(accommodationRepository.findAllByMember(member) + .stream() + .map(AccommodationResponse::fromEntity) + .toList()); } @Cacheable(value = "rooms", key = "#accommodationId",cacheManager = "contentCacheManager") - public List getRooms(JwtPrincipal jwtPrincipal, Long accommodationId) { + public WrapRoomResponse getRooms(JwtPrincipal jwtPrincipal, Long accommodationId) { Long memberId = Long.parseLong(jwtPrincipal.getMemberId()); Member member = memberRepository.findById(memberId) @@ -46,9 +49,10 @@ public List getRooms(JwtPrincipal jwtPrincipal, Long accommodation Accommodation accommodation = accommodationRepository.findById(accommodationId) .orElseThrow(AccommodationNotFoundException::new); - return roomRepository.findAllByAccommodation(accommodation) + return WrapRoomResponse + .from(roomRepository.findAllByAccommodation(accommodation) .stream() .map(RoomResponse::fromEntity) - .toList(); + .toList()); } } From 8f53ff0fb06dc218cef3cf282fd4376ab76b1611 Mon Sep 17 00:00:00 2001 From: KwonJuHwan <118177454+KwonJuHwan@users.noreply.github.com> Date: Tue, 23 Jan 2024 15:16:23 +0900 Subject: [PATCH 2/2] =?UTF-8?q?[bugfix]=20Wrapper=20=EB=A0=88=EC=BD=94?= =?UTF-8?q?=EB=93=9C=20=EC=B6=94=EA=B0=80=EB=A1=9C=20=EC=9D=B8=ED=95=9C,?= =?UTF-8?q?=20Controller,=20test=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/AccommodationController.java | 6 +++-- .../AccommodationControllerTest.java | 22 +++++++++---------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/coolpeace/domain/accommodation/controller/AccommodationController.java b/src/main/java/com/coolpeace/domain/accommodation/controller/AccommodationController.java index 15aaffcb..184822e8 100644 --- a/src/main/java/com/coolpeace/domain/accommodation/controller/AccommodationController.java +++ b/src/main/java/com/coolpeace/domain/accommodation/controller/AccommodationController.java @@ -2,6 +2,8 @@ import com.coolpeace.domain.accommodation.dto.response.AccommodationResponse; import com.coolpeace.domain.accommodation.dto.response.RoomResponse; +import com.coolpeace.domain.accommodation.dto.response.WrapAccommodationResponse; +import com.coolpeace.domain.accommodation.dto.response.WrapRoomResponse; import com.coolpeace.domain.accommodation.service.AccomodationService; import com.coolpeace.global.jwt.security.JwtPrincipal; import com.coolpeace.global.resolver.AuthJwtPrincipal; @@ -21,14 +23,14 @@ public class AccommodationController { private final AccomodationService accomodationService; @GetMapping - public ResponseEntity> accommodations( + public ResponseEntity accommodations( @AuthJwtPrincipal JwtPrincipal jwtPrincipal ) { return ResponseEntity.ok(accomodationService.getAccommodations(jwtPrincipal)); } @GetMapping("/{accommodationId}") - public ResponseEntity> rooms( + public ResponseEntity rooms( @AuthJwtPrincipal JwtPrincipal jwtPrincipal, @PathVariable Long accommodationId ) { diff --git a/src/test/java/com/coolpeace/docs/accommodation/AccommodationControllerTest.java b/src/test/java/com/coolpeace/docs/accommodation/AccommodationControllerTest.java index 46a4be97..8ff32185 100644 --- a/src/test/java/com/coolpeace/docs/accommodation/AccommodationControllerTest.java +++ b/src/test/java/com/coolpeace/docs/accommodation/AccommodationControllerTest.java @@ -88,13 +88,13 @@ void selectAccommodations() throws Exception { .description("숙소 목록 조회 API") .responseSchema(Schema.schema(AccommodationResponse.class.getSimpleName())) .responseFields( - fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("숙소 ID"), - fieldWithPath("[].name").type(JsonFieldType.STRING).description("숙소명"), - fieldWithPath("[].sido_id").type(JsonFieldType.NUMBER).description("시도ID"), - fieldWithPath("[].sido").type(JsonFieldType.STRING).description("시도명"), - fieldWithPath("[].sigungu_id").type(JsonFieldType.NUMBER).description("시군구ID"), - fieldWithPath("[].sigungu").type(JsonFieldType.STRING).description("시군구명"), - fieldWithPath("[].address").type(JsonFieldType.STRING).description("숙소 상세") + fieldWithPath(".accommodation_responses[].id").type(JsonFieldType.NUMBER).description("숙소 ID"), + fieldWithPath(".accommodation_responses[].name").type(JsonFieldType.STRING).description("숙소명"), + fieldWithPath(".accommodation_responses[].sido_id").type(JsonFieldType.NUMBER).description("시도ID"), + fieldWithPath(".accommodation_responses[].sido").type(JsonFieldType.STRING).description("시도명"), + fieldWithPath(".accommodation_responses[].sigungu_id").type(JsonFieldType.NUMBER).description("시군구ID"), + fieldWithPath(".accommodation_responses[].sigungu").type(JsonFieldType.STRING).description("시군구명"), + fieldWithPath(".accommodation_responses[].address").type(JsonFieldType.STRING).description("숙소 상세") ) .build() ) @@ -123,10 +123,10 @@ void selectAccommodationRooms() throws Exception { .description("숙소의 객실 목록 조회 API") .responseSchema(Schema.schema(RoomResponse.class.getSimpleName())) .responseFields( - fieldWithPath("[].id").type(JsonFieldType.NUMBER).description("방ID"), - fieldWithPath("[].room_number").type(JsonFieldType.STRING).description("방번호"), - fieldWithPath("[].room_type").type(JsonFieldType.STRING).description("방타입"), - fieldWithPath("[].price").type(JsonFieldType.NUMBER).description("가격") + fieldWithPath(".room_responses[].id").type(JsonFieldType.NUMBER).description("방ID"), + fieldWithPath(".room_responses[].room_number").type(JsonFieldType.STRING).description("방번호"), + fieldWithPath(".room_responses[].room_type").type(JsonFieldType.STRING).description("방타입"), + fieldWithPath(".room_responses[].price").type(JsonFieldType.NUMBER).description("가격") ) .build() )));