Skip to content

Commit

Permalink
Merge pull request #178 from CoolPeace-yanolza/develop
Browse files Browse the repository at this point in the history
01.23 15시 배포
  • Loading branch information
KwonJuHwan authored Jan 23, 2024
2 parents 9251cd7 + a97c257 commit ee81c59
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,14 +23,14 @@ public class AccommodationController {
private final AccomodationService accomodationService;

@GetMapping
public ResponseEntity<List<AccommodationResponse>> accommodations(
public ResponseEntity<WrapAccommodationResponse> accommodations(
@AuthJwtPrincipal JwtPrincipal jwtPrincipal
) {
return ResponseEntity.ok(accomodationService.getAccommodations(jwtPrincipal));
}

@GetMapping("/{accommodationId}")
public ResponseEntity<List<RoomResponse>> rooms(
public ResponseEntity<WrapRoomResponse> rooms(
@AuthJwtPrincipal JwtPrincipal jwtPrincipal,
@PathVariable Long accommodationId
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.coolpeace.domain.accommodation.dto.response;

import java.util.List;

public record WrapAccommodationResponse(
List<AccommodationResponse> accommodationResponses
) {
public static WrapAccommodationResponse from(List<AccommodationResponse> accommodationResponses) {
return new WrapAccommodationResponse(accommodationResponses);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.coolpeace.domain.accommodation.dto.response;

import java.util.List;

public record WrapRoomResponse(
List<RoomResponse> roomResponses
) {
public static WrapRoomResponse from(List<RoomResponse> roomResponses) {
return new WrapRoomResponse(roomResponses);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,20 +26,21 @@ public class AccomodationService {
private final RoomRepository roomRepository;

@Cacheable(value = "accommodation", key = "#jwtPrincipal.toString()",cacheManager = "contentCacheManager")
public List<AccommodationResponse> 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<RoomResponse> getRooms(JwtPrincipal jwtPrincipal, Long accommodationId) {
public WrapRoomResponse getRooms(JwtPrincipal jwtPrincipal, Long accommodationId) {

Long memberId = Long.parseLong(jwtPrincipal.getMemberId());
Member member = memberRepository.findById(memberId)
Expand All @@ -46,9 +49,10 @@ public List<RoomResponse> 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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand Down Expand Up @@ -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()
)));
Expand Down

0 comments on commit ee81c59

Please sign in to comment.