Skip to content

Commit

Permalink
fix: totalPrice 반환하도록 AccommodationService.readAll 수정
Browse files Browse the repository at this point in the history
Dae-Hwa/airbnb/#45
  • Loading branch information
Dae-Hwa committed May 31, 2021
1 parent fc737c2 commit 4eae755
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public static AccommodationDTO from(Accommodation accommodation) {
.build();
}

public static AccommodationDTO from(Accommodation accommodation, int nights) {
public static AccommodationDTO of(Accommodation accommodation, int nights) {
return builder().id(accommodation.getId())
.name(accommodation.getName())
.accommodationOption(accommodation.getAccommodationOption())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static AccommodationResponse from(Accommodation accommodation) {
.build();
}

public static AccommodationResponse from(Accommodation accommodation, int nights) {
public static AccommodationResponse of(Accommodation accommodation, int nights) {
return builder().id(accommodation.getId())
.name(accommodation.getName())
.accommodationOption(accommodation.getAccommodationOption())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public AccommodationServiceImpl(AccommodationRepository accommodationRepository)
@Override
public List<AccommodationResponse> readAll(AccommodationRequest accommodationRequest) {
return accommodationRepository.findAllBy(accommodationRequest).stream()
.map(AccommodationResponse::from)
.map(accommodation -> AccommodationResponse.of(accommodation, accommodationRequest.nights()))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
@Profile("mockup")
public class AccommodationServiceMockup implements AccommodationService {
public List<AccommodationResponse> readAll(AccommodationRequest accommodationRequest) {
List<AccommodationResponse> result = DummyDataFactory.accommodationResponseDTOsWithId();
List<AccommodationResponse> result = DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight();

if (accommodationRequest.getStartPrice() != null) {
result = result.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public static AccommodationBuilder accommodationBuilderTypeOneRoom() {
.mainImage("https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg")
.images(Arrays.asList("https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg", "https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg"))
.description("롤로호텔 일반객실입니다.")
.accommodationHost(accommodationHost());
.accommodationHost(accommodationHost())
.accommodationPrice(Price.from(200000));
}

public static AccommodationBuilder accommodationBuilderTypeLowQuality() {
Expand All @@ -97,7 +98,8 @@ public static AccommodationBuilder accommodationBuilderTypeLowQuality() {
.mainImage("https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg")
.images(Arrays.asList("https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg", "https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg"))
.description("프레디 여관입니다.")
.accommodationHost(accommodationHost());
.accommodationHost(accommodationHost())
.accommodationPrice(Price.from(40000));
}

public static List<Accommodation> accommodations() {
Expand All @@ -116,15 +118,21 @@ public static List<Accommodation> accommodationsWithId() {
);
}

public static List<AccommodationResponse> accommodationResponseDTOs() {
public static List<AccommodationResponse> accommodationResponseDTOsTypeOneNight() {
return accommodations().stream()
.map(AccommodationResponse::from)
.map(accommodation -> AccommodationResponse.of(accommodation,1))
.collect(Collectors.toList());
}

public static List<AccommodationResponse> accommodationResponseDTOsWithIdTypeOneNight() {
return accommodationsWithId().stream()
.map(accommodation -> AccommodationResponse.of(accommodation,1))
.collect(Collectors.toList());
}

public static List<AccommodationResponse> accommodationResponseDTOsWithId() {
public static List<AccommodationResponse> accommodationResponseDTOsWithIdTypeTwoNights() {
return accommodationsWithId().stream()
.map(AccommodationResponse::from)
.map(accommodation -> AccommodationResponse.of(accommodation,2))
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,23 +59,23 @@ static Stream<Arguments> readAllProvider() {
Arguments.arguments(
"/accommodations",
AccommodationRequest.builder().build(),
DummyDataFactory.accommodationResponseDTOsWithId()
DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight()
), Arguments.arguments(
"/accommodations",
AccommodationRequest.builder().endPrice(300000).build(),
DummyDataFactory.accommodationResponseDTOsWithId().stream()
DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream()
.filter(accommodationResponseDTO -> accommodationResponseDTO.pricePerNight() <= 300000)
.collect(Collectors.toList())
), Arguments.arguments(
"/accommodations",
AccommodationRequest.builder().startPrice(100000).build(),
DummyDataFactory.accommodationResponseDTOsWithId().stream()
DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream()
.filter(accommodationResponseDTO -> 100000 <= accommodationResponseDTO.pricePerNight())
.collect(Collectors.toList())
), Arguments.arguments(
"/accommodations",
AccommodationRequest.builder().startPrice(100000).endPrice(300000).build(),
DummyDataFactory.accommodationResponseDTOsWithId().stream()
DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream()
.filter(accommodationResponseDTO -> 100000 <= accommodationResponseDTO.pricePerNight())
.filter(accommodationResponseDTO -> accommodationResponseDTO.pricePerNight() <= 300000)
.collect(Collectors.toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,21 @@ void readAll(AccommodationRequest accommodationRequest, List<Accommodation> give
static Stream<Arguments> readAllProvider() {
return Stream.of(
Arguments.of(
AccommodationRequest.builder().endPrice(300000).build(),
AccommodationRequest.builder().build(),
DummyDataFactory.accommodationsWithId().stream()
.collect(Collectors.toList()),
DummyDataFactory.accommodationResponseDTOsWithId().stream()
DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream()
.collect(Collectors.toList())
),
Arguments.of(
AccommodationRequest.builder()
.checkinDate(LocalDate.now())
.checkoutDate(LocalDate.now().plusDays(2))
.build(),
DummyDataFactory.accommodationsWithId().stream()
.collect(Collectors.toList()),
DummyDataFactory.accommodationsWithId().stream()
.map(accommodation -> AccommodationResponse.of(accommodation, 2))
.collect(Collectors.toList())
)
);
Expand Down

0 comments on commit 4eae755

Please sign in to comment.