From 3cf2ad9aae1d4ff52d6e34cd858c6e807fc0be92 Mon Sep 17 00:00:00 2001 From: Dae-Hwa Date: Tue, 1 Jun 2021 03:16:07 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=EB=8D=94=EB=AF=B8=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=84=B0=20=ED=8C=A9=ED=86=A0=EB=A6=AC=20=EA=B0=81=20?= =?UTF-8?q?=ED=83=80=EC=9E=85=EB=B3=84=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 너무 많아져서 관리가 힘들어짐. --- .../controller/AccommodationController.java | 5 +- .../repository/AccommodationRepository.java | 6 +- .../service/AccommodationServiceMockup.java | 10 +- .../AccommodationDTODummyDataFactory.java | 16 ++ .../AccommodationDummyDataFactory.java | 68 ++++++ .../AccommodationHostDummyDataFactory.java | 12 + .../AccommodationOptionDummyDataFactory.java | 54 +++++ ...commodationPriceStatsDummyDataFactory.java | 18 ++ ...dationReservationInfoDummyDataFactory.java | 49 ++++ ...AccommodationResponseDummyDataFactory.java | 28 +++ .../ReservationDTODummyDataFactory.java | 19 ++ .../WishlistItemDTODummyDataFactory.java | 20 ++ .../airbnb/common/utils/DummyDataFactory.java | 210 ------------------ .../controller/ReservationController.java | 6 +- .../airbnb/wishlist/WishlistController.java | 4 +- .../AccommodationControllerTest.java | 19 +- .../service/AccommodationServiceImplTest.java | 24 +- .../controller/ReservationControllerTest.java | 6 +- .../wishlist/WishlistControllerTest.java | 4 +- 19 files changed, 329 insertions(+), 249 deletions(-) create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDTODummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationHostDummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationOptionDummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationPriceStatsDummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationReservationInfoDummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationResponseDummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/ReservationDTODummyDataFactory.java create mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/WishlistItemDTODummyDataFactory.java delete mode 100644 BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/utils/DummyDataFactory.java diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/controller/AccommodationController.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/controller/AccommodationController.java index 44da3987f..ca0739a55 100644 --- a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/controller/AccommodationController.java +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/controller/AccommodationController.java @@ -1,10 +1,9 @@ package com.codesquad.airbnb.accommodation.controller; import com.codesquad.airbnb.accommodation.service.AccommodationService; -import com.codesquad.airbnb.common.utils.DummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationPriceStatsDummyDataFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; import javax.validation.Valid; @@ -31,7 +30,7 @@ public AccommodationDTO readOne(@PathVariable long id) { @GetMapping("/accommodationPriceStats") public List priceStats() { - return DummyDataFactory.accommodationPriceStats(); + return AccommodationPriceStatsDummyDataFactory.list(); } @GetMapping("/accommodations/{id}/reservation") diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/repository/AccommodationRepository.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/repository/AccommodationRepository.java index c0add6d04..e3d80762e 100644 --- a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/repository/AccommodationRepository.java +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/repository/AccommodationRepository.java @@ -2,7 +2,7 @@ import com.codesquad.airbnb.accommodation.controller.AccommodationRequest; import com.codesquad.airbnb.accommodation.domain.Accommodation; -import com.codesquad.airbnb.common.utils.DummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationDummyDataFactory; import org.springframework.stereotype.Repository; import java.util.List; @@ -10,11 +10,11 @@ @Repository public class AccommodationRepository { public List findAllBy(AccommodationRequest accommodationRequest) { - return DummyDataFactory.accommodationsWithId(); + return AccommodationDummyDataFactory.listWithId(); } public Accommodation findOne(long id) { - return DummyDataFactory.accommodationsWithId().stream() + return AccommodationDummyDataFactory.listWithId().stream() .filter(accommodation -> accommodation.getId() == id) .findAny() .get(); diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceMockup.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceMockup.java index 5cae04bd3..10ba60277 100644 --- a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceMockup.java +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceMockup.java @@ -4,8 +4,10 @@ import com.codesquad.airbnb.accommodation.controller.AccommodationRequest; import com.codesquad.airbnb.accommodation.controller.AccommodationReservationInfo; import com.codesquad.airbnb.accommodation.controller.AccommodationResponse; +import com.codesquad.airbnb.common.dummydata.AccommodationDTODummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationReservationInfoDummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationResponseDummyDataFactory; import com.codesquad.airbnb.common.exception.NotFoundException; -import com.codesquad.airbnb.common.utils.DummyDataFactory; import org.springframework.context.annotation.Profile; import org.springframework.stereotype.Service; @@ -16,7 +18,7 @@ @Profile("mockup") public class AccommodationServiceMockup implements AccommodationService { public List readAll(AccommodationRequest accommodationRequest) { - List result = DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight(); + List result = AccommodationResponseDummyDataFactory.listWithIdTypeOneNight(); if (accommodationRequest.getStartPrice() != null) { result = result.stream() @@ -34,7 +36,7 @@ public List readAll(AccommodationRequest accommodationReq } public AccommodationDTO readOne(long id) { - List result = DummyDataFactory.accommodationDTOsWithId(); + List result = AccommodationDTODummyDataFactory.listWithId(); return result.stream() .filter(accommodationDTO -> accommodationDTO.getId() == id) @@ -44,6 +46,6 @@ public AccommodationDTO readOne(long id) { @Override public AccommodationReservationInfo accommodationReservationInfo(long id, AccommodationRequest accommodationRequest) { - return DummyDataFactory.accommodationReservationInfoTypeSuiteRoomOnePersonOneDay(); + return AccommodationReservationInfoDummyDataFactory.suiteRoomOnePersonOneDay(); } } diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDTODummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDTODummyDataFactory.java new file mode 100644 index 000000000..c310f472e --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDTODummyDataFactory.java @@ -0,0 +1,16 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.controller.AccommodationDTO; + +import java.util.List; +import java.util.stream.Collectors; + +public class AccommodationDTODummyDataFactory { + private AccommodationDTODummyDataFactory(){} + + public static List listWithId() { + return AccommodationDummyDataFactory.listWithId().stream() + .map(AccommodationDTO::from) + .collect(Collectors.toList()); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDummyDataFactory.java new file mode 100644 index 000000000..67fc7a4b3 --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationDummyDataFactory.java @@ -0,0 +1,68 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.domain.Accommodation; +import com.codesquad.airbnb.accommodation.domain.AccommodationBuilder; +import com.codesquad.airbnb.accommodation.domain.price.Price; + +import java.util.Arrays; +import java.util.List; + +public class AccommodationDummyDataFactory { + private AccommodationDummyDataFactory() { + } + + public static AccommodationBuilder builderWithSuiteRoom() { + return Accommodation.builder() + .name("어텀호텔 스위트룸") + .accommodationOption(AccommodationOptionDummyDataFactory.normal()) + .reviewRating(4.8) + .reviewCounts(5) + .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(AccommodationHostDummyDataFactory.create()) + .accommodationPrice(Price.from(400000)); + } + + public static AccommodationBuilder builderWithOneRoom() { + return Accommodation.builder() + .name("롤로호텔 일반객실") + .accommodationOption(AccommodationOptionDummyDataFactory.oneRoom()) + .reviewRating(4.2) + .reviewCounts(5) + .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(AccommodationHostDummyDataFactory.create()) + .accommodationPrice(Price.from(200000)); + } + + public static AccommodationBuilder builderWithLowQuality() { + return Accommodation.builder() + .name("프레디 여관") + .accommodationOption(AccommodationOptionDummyDataFactory.publicRestroom()) + .reviewRating(3.1) + .reviewCounts(5) + .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(AccommodationHostDummyDataFactory.create()) + .accommodationPrice(Price.from(40000)); + } + + public static List list() { + return Arrays.asList( + builderWithSuiteRoom().build(), + builderWithOneRoom().build(), + builderWithLowQuality().build() + ); + } + + public static List listWithId() { + return Arrays.asList( + builderWithSuiteRoom().id(1L).build(), + builderWithOneRoom().id(2L).build(), + builderWithLowQuality().id(3L).build() + ); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationHostDummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationHostDummyDataFactory.java new file mode 100644 index 000000000..9fcb80bd6 --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationHostDummyDataFactory.java @@ -0,0 +1,12 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.controller.AccommodationHost; + +public class AccommodationHostDummyDataFactory { + private AccommodationHostDummyDataFactory() { + } + + public static AccommodationHost create() { + return new AccommodationHost(1L, "name", "https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg"); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationOptionDummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationOptionDummyDataFactory.java new file mode 100644 index 000000000..850b515af --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationOptionDummyDataFactory.java @@ -0,0 +1,54 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.domain.AccommodationOption; +import com.codesquad.airbnb.accommodation.domain.AccommodationType; +import com.codesquad.airbnb.accommodation.domain.RestroomType; + +public class AccommodationOptionDummyDataFactory { + private AccommodationOptionDummyDataFactory(){} + + public static AccommodationOption normal() { + return AccommodationOption.builder() + .capacity(8) + .pricePerNight(400000) + .accommodationType(AccommodationType.NORMAL) + .bedroomCount(3) + .restroomCount(2) + .restroomType(RestroomType.PRIVATE) + .hasKitchen(false) + .hasInternet(true) + .hasAirconditioner(true) + .hasHairdrier(true) + .build(); + } + + public static AccommodationOption oneRoom() { + return AccommodationOption.builder() + .capacity(4) + .pricePerNight(200000) + .accommodationType(AccommodationType.ONEROOM) + .bedroomCount(1) + .restroomCount(1) + .restroomType(RestroomType.PRIVATE) + .hasKitchen(false) + .hasInternet(true) + .hasAirconditioner(true) + .hasHairdrier(true) + .build(); + } + + public static AccommodationOption publicRestroom() { + return AccommodationOption.builder() + .capacity(2) + .pricePerNight(40000) + .accommodationType(AccommodationType.ONEROOM) + .bedroomCount(1) + .restroomCount(1) + .restroomType(RestroomType.PUBLIC) + .hasKitchen(false) + .hasInternet(false) + .hasAirconditioner(true) + .hasHairdrier(true) + .build(); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationPriceStatsDummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationPriceStatsDummyDataFactory.java new file mode 100644 index 000000000..5e697effa --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationPriceStatsDummyDataFactory.java @@ -0,0 +1,18 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.controller.AccommodationPriceStats; + +import java.util.Arrays; +import java.util.List; + +public class AccommodationPriceStatsDummyDataFactory { + private AccommodationPriceStatsDummyDataFactory(){} + + public static List list() { + return Arrays.asList( + new AccommodationPriceStats(10000, 10), + new AccommodationPriceStats(30000, 11), + new AccommodationPriceStats(20000, 21) + ); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationReservationInfoDummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationReservationInfoDummyDataFactory.java new file mode 100644 index 000000000..270302c28 --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationReservationInfoDummyDataFactory.java @@ -0,0 +1,49 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.controller.AccommodationReservationInfo; + +public class AccommodationReservationInfoDummyDataFactory { + private AccommodationReservationInfoDummyDataFactory(){} + + public static AccommodationReservationInfo suiteRoomOnePersonOneDay() { + return AccommodationReservationInfo.builder() + .id(1L) + .pricePerNight(400000) + .priceForNights(400000) + .discountPrice(16000) + .cleaningFee(20000) + .serviceFee(40000) + .accommodationTax(20000) + .totalPrice(464000) + .reviewCounts(5) + .build(); + } + + public static AccommodationReservationInfo suiteRoomOnePersonTwoDays() { + return AccommodationReservationInfo.builder() + .id(1L) + .pricePerNight(400000) + .priceForNights(800000) + .discountPrice(32000) + .cleaningFee(40000) + .serviceFee(80000) + .accommodationTax(40000) + .totalPrice(928000) + .reviewCounts(5) + .build(); + } + + public static AccommodationReservationInfo suiteRoomTwoPerson() { + return AccommodationReservationInfo.builder() + .id(1L) + .pricePerNight(400000) + .priceForNights(800000) + .discountPrice(32000) + .cleaningFee(40000) + .serviceFee(80000) + .accommodationTax(40000) + .totalPrice(928000) + .reviewCounts(5) + .build(); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationResponseDummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationResponseDummyDataFactory.java new file mode 100644 index 000000000..deee9d01c --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/AccommodationResponseDummyDataFactory.java @@ -0,0 +1,28 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.controller.AccommodationResponse; + +import java.util.List; +import java.util.stream.Collectors; + +public class AccommodationResponseDummyDataFactory { + private AccommodationResponseDummyDataFactory(){} + + public static List listWithOneNight() { + return AccommodationDummyDataFactory.list().stream() + .map(accommodation -> AccommodationResponse.of(accommodation,1)) + .collect(Collectors.toList()); + } + + public static List listWithIdTypeOneNight() { + return AccommodationDummyDataFactory.listWithId().stream() + .map(accommodation -> AccommodationResponse.of(accommodation,1)) + .collect(Collectors.toList()); + } + + public static List listWithIdTypeTwoNights() { + return AccommodationDummyDataFactory.listWithId().stream() + .map(accommodation -> AccommodationResponse.of(accommodation,2)) + .collect(Collectors.toList()); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/ReservationDTODummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/ReservationDTODummyDataFactory.java new file mode 100644 index 000000000..68d8dca2c --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/ReservationDTODummyDataFactory.java @@ -0,0 +1,19 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.controller.AccommodationResponse; +import com.codesquad.airbnb.reservation.controller.ReservationDTO; + +import java.util.Arrays; +import java.util.List; + +public class ReservationDTODummyDataFactory { + private ReservationDTODummyDataFactory(){} + + public static List list() { + return Arrays.asList(create(), create()); + } + + public static ReservationDTO create() { + return new ReservationDTO(1L, AccommodationResponse.from(AccommodationDummyDataFactory.builderWithSuiteRoom().build())); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/WishlistItemDTODummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/WishlistItemDTODummyDataFactory.java new file mode 100644 index 000000000..e8221477c --- /dev/null +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/dummydata/WishlistItemDTODummyDataFactory.java @@ -0,0 +1,20 @@ +package com.codesquad.airbnb.common.dummydata; + +import com.codesquad.airbnb.accommodation.controller.AccommodationResponse; +import com.codesquad.airbnb.wishlist.WishlistItemDTO; + +import java.util.Arrays; +import java.util.List; + +public class WishlistItemDTODummyDataFactory { + private WishlistItemDTODummyDataFactory() { + } + + public static List list() { + return Arrays.asList(create(), create()); + } + + public static WishlistItemDTO create() { + return new WishlistItemDTO(1L, AccommodationResponse.from(AccommodationDummyDataFactory.builderWithSuiteRoom().build())); + } +} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/utils/DummyDataFactory.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/utils/DummyDataFactory.java deleted file mode 100644 index 791b7e17e..000000000 --- a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/common/utils/DummyDataFactory.java +++ /dev/null @@ -1,210 +0,0 @@ -package com.codesquad.airbnb.common.utils; - -import com.codesquad.airbnb.accommodation.controller.*; -import com.codesquad.airbnb.accommodation.domain.*; -import com.codesquad.airbnb.accommodation.domain.price.Price; -import com.codesquad.airbnb.reservation.controller.ReservationDTO; -import com.codesquad.airbnb.wishlist.WishlistItemDTO; - -import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; - -public class DummyDataFactory { - private DummyDataFactory() { - } - - public static AccommodationOption accommodationOptionOfNormal() { - return AccommodationOption.builder() - .capacity(8) - .pricePerNight(400000) - .accommodationType(AccommodationType.NORMAL) - .bedroomCount(3) - .restroomCount(2) - .restroomType(RestroomType.PRIVATE) - .hasKitchen(false) - .hasInternet(true) - .hasAirconditioner(true) - .hasHairdrier(true) - .build(); - } - - public static AccommodationOption accommodationOptionOfOneroom() { - return AccommodationOption.builder() - .capacity(4) - .pricePerNight(200000) - .accommodationType(AccommodationType.ONEROOM) - .bedroomCount(1) - .restroomCount(1) - .restroomType(RestroomType.PRIVATE) - .hasKitchen(false) - .hasInternet(true) - .hasAirconditioner(true) - .hasHairdrier(true) - .build(); - } - - public static AccommodationOption accommodationOptionOfPublicRestroom() { - return AccommodationOption.builder() - .capacity(2) - .pricePerNight(40000) - .accommodationType(AccommodationType.ONEROOM) - .bedroomCount(1) - .restroomCount(1) - .restroomType(RestroomType.PUBLIC) - .hasKitchen(false) - .hasInternet(false) - .hasAirconditioner(true) - .hasHairdrier(true) - .build(); - } - - public static AccommodationHost accommodationHost() { - return new AccommodationHost(1L, "name", "https://image.zdnet.co.kr/2016/12/08/imc_47ix3fAqITYz5QtR.jpg"); - } - - public static AccommodationBuilder accommodationBuilderTypeSuiteRoom() { - return Accommodation.builder() - .name("어텀호텔 스위트룸") - .accommodationOption(accommodationOptionOfNormal()) - .reviewRating(4.8) - .reviewCounts(5) - .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()) - .accommodationPrice(Price.from(400000)); - } - - public static AccommodationBuilder accommodationBuilderTypeOneRoom() { - return Accommodation.builder() - .name("롤로호텔 일반객실") - .accommodationOption(accommodationOptionOfOneroom()) - .reviewRating(4.2) - .reviewCounts(5) - .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()) - .accommodationPrice(Price.from(200000)); - } - - public static AccommodationBuilder accommodationBuilderTypeLowQuality() { - return Accommodation.builder() - .name("프레디 여관") - .accommodationOption(accommodationOptionOfPublicRestroom()) - .reviewRating(3.1) - .reviewCounts(5) - .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()) - .accommodationPrice(Price.from(40000)); - } - - public static List accommodations() { - return Arrays.asList( - DummyDataFactory.accommodationBuilderTypeSuiteRoom().build(), - DummyDataFactory.accommodationBuilderTypeOneRoom().build(), - DummyDataFactory.accommodationBuilderTypeLowQuality().build() - ); - } - - public static List accommodationsWithId() { - return Arrays.asList( - DummyDataFactory.accommodationBuilderTypeSuiteRoom().id(1L).build(), - DummyDataFactory.accommodationBuilderTypeOneRoom().id(2L).build(), - DummyDataFactory.accommodationBuilderTypeLowQuality().id(3L).build() - ); - } - - public static List accommodationResponseDTOsTypeOneNight() { - return accommodations().stream() - .map(accommodation -> AccommodationResponse.of(accommodation,1)) - .collect(Collectors.toList()); - } - - public static List accommodationResponseDTOsWithIdTypeOneNight() { - return accommodationsWithId().stream() - .map(accommodation -> AccommodationResponse.of(accommodation,1)) - .collect(Collectors.toList()); - } - - public static List accommodationResponseDTOsWithIdTypeTwoNights() { - return accommodationsWithId().stream() - .map(accommodation -> AccommodationResponse.of(accommodation,2)) - .collect(Collectors.toList()); - } - - public static List accommodationDTOsWithId() { - return accommodationsWithId().stream() - .map(AccommodationDTO::from) - .collect(Collectors.toList()); - } - - public static List accommodationPriceStats() { - return Arrays.asList( - new AccommodationPriceStats(10000, 10), - new AccommodationPriceStats(30000, 11), - new AccommodationPriceStats(20000, 21) - ); - } - - public static AccommodationReservationInfo accommodationReservationInfoTypeSuiteRoomOnePersonOneDay() { - return AccommodationReservationInfo.builder() - .id(1L) - .pricePerNight(400000) - .priceForNights(400000) - .discountPrice(16000) - .cleaningFee(20000) - .serviceFee(40000) - .accommodationTax(20000) - .totalPrice(464000) - .reviewCounts(5) - .build(); - } - - public static AccommodationReservationInfo accommodationReservationInfoTypeSuiteRoomOnePersonTwoDays() { - return AccommodationReservationInfo.builder() - .id(1L) - .pricePerNight(400000) - .priceForNights(800000) - .discountPrice(32000) - .cleaningFee(40000) - .serviceFee(80000) - .accommodationTax(40000) - .totalPrice(928000) - .reviewCounts(5) - .build(); - } - - public static AccommodationReservationInfo accommodationReservationInfoTypeSuiteRoomTwoPerson() { - return AccommodationReservationInfo.builder() - .id(1L) - .pricePerNight(400000) - .priceForNights(800000) - .discountPrice(32000) - .cleaningFee(40000) - .serviceFee(80000) - .accommodationTax(40000) - .totalPrice(928000) - .reviewCounts(5) - .build(); - } - - public static List reservations() { - return Arrays.asList(DummyDataFactory.reservation(), DummyDataFactory.reservation()); - } - - public static ReservationDTO reservation() { - return new ReservationDTO(1L, AccommodationResponse.from(accommodationBuilderTypeSuiteRoom().build())); - } - - public static List wishlist() { - return Arrays.asList(DummyDataFactory.wishlistItem(), DummyDataFactory.wishlistItem()); - } - - public static WishlistItemDTO wishlistItem() { - return new WishlistItemDTO(1L, AccommodationResponse.from(accommodationBuilderTypeSuiteRoom().build())); - } -} diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/reservation/controller/ReservationController.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/reservation/controller/ReservationController.java index a317cfab5..addef2235 100644 --- a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/reservation/controller/ReservationController.java +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/reservation/controller/ReservationController.java @@ -1,6 +1,6 @@ package com.codesquad.airbnb.reservation.controller; -import com.codesquad.airbnb.common.utils.DummyDataFactory; +import com.codesquad.airbnb.common.dummydata.ReservationDTODummyDataFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @@ -12,11 +12,11 @@ public class ReservationController { @GetMapping("/users/{userId}/reservations") public List readAll(@PathVariable long userId) { - return DummyDataFactory.reservations(); + return ReservationDTODummyDataFactory.list(); } @GetMapping("/users/{userId}/reservations/{reservationId}") public ReservationDTO readOne(@PathVariable long userId, @PathVariable long reservationId) { - return DummyDataFactory.reservation(); + return ReservationDTODummyDataFactory.create(); } } diff --git a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/wishlist/WishlistController.java b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/wishlist/WishlistController.java index 3efbd2950..12500a53f 100644 --- a/BE/airbnb-be/src/main/java/com/codesquad/airbnb/wishlist/WishlistController.java +++ b/BE/airbnb-be/src/main/java/com/codesquad/airbnb/wishlist/WishlistController.java @@ -1,6 +1,6 @@ package com.codesquad.airbnb.wishlist; -import com.codesquad.airbnb.common.utils.DummyDataFactory; +import com.codesquad.airbnb.common.dummydata.WishlistItemDTODummyDataFactory; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; @@ -12,6 +12,6 @@ public class WishlistController { @GetMapping("/users/{userId}/wishlist") public List readAll(@PathVariable long userId) { - return DummyDataFactory.wishlist(); + return WishlistItemDTODummyDataFactory.list(); } } diff --git a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/controller/AccommodationControllerTest.java b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/controller/AccommodationControllerTest.java index b3d752e90..d421e6194 100644 --- a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/controller/AccommodationControllerTest.java +++ b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/controller/AccommodationControllerTest.java @@ -1,8 +1,11 @@ package com.codesquad.airbnb.accommodation.controller; +import com.codesquad.airbnb.common.dummydata.AccommodationDTODummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationPriceStatsDummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationReservationInfoDummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationResponseDummyDataFactory; import com.codesquad.airbnb.common.exception.ErrorResponse; import com.codesquad.airbnb.common.exception.NotFoundException; -import com.codesquad.airbnb.common.utils.DummyDataFactory; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -59,23 +62,23 @@ static Stream readAllProvider() { Arguments.arguments( "/accommodations", AccommodationRequest.builder().build(), - DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight() + AccommodationResponseDummyDataFactory.listWithIdTypeOneNight() ), Arguments.arguments( "/accommodations", AccommodationRequest.builder().endPrice(300000).build(), - DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream() + AccommodationResponseDummyDataFactory.listWithIdTypeOneNight().stream() .filter(accommodationResponseDTO -> accommodationResponseDTO.pricePerNight() <= 300000) .collect(Collectors.toList()) ), Arguments.arguments( "/accommodations", AccommodationRequest.builder().startPrice(100000).build(), - DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream() + AccommodationResponseDummyDataFactory.listWithIdTypeOneNight().stream() .filter(accommodationResponseDTO -> 100000 <= accommodationResponseDTO.pricePerNight()) .collect(Collectors.toList()) ), Arguments.arguments( "/accommodations", AccommodationRequest.builder().startPrice(100000).endPrice(300000).build(), - DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream() + AccommodationResponseDummyDataFactory.listWithIdTypeOneNight().stream() .filter(accommodationResponseDTO -> 100000 <= accommodationResponseDTO.pricePerNight()) .filter(accommodationResponseDTO -> accommodationResponseDTO.pricePerNight() <= 300000) .collect(Collectors.toList()) @@ -182,7 +185,7 @@ static Stream readOneProvider() { Arguments.of( "/accommodations/{id}", 1, - DummyDataFactory.accommodationDTOsWithId().stream() + AccommodationDTODummyDataFactory.listWithId().stream() .filter(accommodationDTO -> accommodationDTO.getId() == 1) .findAny() .orElseThrow(() -> new NotFoundException()) @@ -213,7 +216,7 @@ static Stream priceStatsProvider() { return Stream.of( Arguments.of( "/accommodationPriceStats", - DummyDataFactory.accommodationPriceStats() + AccommodationPriceStatsDummyDataFactory.list() ) ); } @@ -243,7 +246,7 @@ static Stream reservationRequestInfoProvider() { "/accommodations/{id}/reservation", 1L, 18, - DummyDataFactory.accommodationReservationInfoTypeSuiteRoomOnePersonOneDay() + AccommodationReservationInfoDummyDataFactory.suiteRoomOnePersonOneDay() ) ); } diff --git a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceImplTest.java b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceImplTest.java index 45997f13d..faddf2b74 100644 --- a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceImplTest.java +++ b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/accommodation/service/AccommodationServiceImplTest.java @@ -5,7 +5,9 @@ import com.codesquad.airbnb.accommodation.controller.AccommodationResponse; import com.codesquad.airbnb.accommodation.domain.Accommodation; import com.codesquad.airbnb.accommodation.repository.AccommodationRepository; -import com.codesquad.airbnb.common.utils.DummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationDummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationReservationInfoDummyDataFactory; +import com.codesquad.airbnb.common.dummydata.AccommodationResponseDummyDataFactory; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; @@ -50,9 +52,9 @@ static Stream readAllProvider() { return Stream.of( Arguments.of( AccommodationRequest.builder().build(), - DummyDataFactory.accommodationsWithId().stream() + AccommodationDummyDataFactory.listWithId().stream() .collect(Collectors.toList()), - DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight().stream() + AccommodationResponseDummyDataFactory.listWithIdTypeOneNight().stream() .collect(Collectors.toList()) ), Arguments.of( @@ -60,9 +62,9 @@ static Stream readAllProvider() { .checkinDate(LocalDate.now()) .checkoutDate(LocalDate.now().plusDays(2)) .build(), - DummyDataFactory.accommodationsWithId().stream() + AccommodationDummyDataFactory.listWithId().stream() .collect(Collectors.toList()), - DummyDataFactory.accommodationsWithId().stream() + AccommodationDummyDataFactory.listWithId().stream() .map(accommodation -> AccommodationResponse.of(accommodation, 2)) .collect(Collectors.toList()) ) @@ -85,28 +87,28 @@ static Stream accommodationReservationInfoProvider() { return Stream.of( Arguments.of( 1L, - DummyDataFactory.accommodationBuilderTypeSuiteRoom().id(1L).build(), + AccommodationDummyDataFactory.builderWithSuiteRoom().id(1L).build(), AccommodationRequest.builder() .checkinDate(LocalDate.now()) .checkoutDate(LocalDate.now().plusDays(1)) .build(), - DummyDataFactory.accommodationReservationInfoTypeSuiteRoomOnePersonOneDay() + AccommodationReservationInfoDummyDataFactory.suiteRoomOnePersonOneDay() ), Arguments.of( 1L, - DummyDataFactory.accommodationBuilderTypeSuiteRoom().id(1L).build(), + AccommodationDummyDataFactory.builderWithSuiteRoom().id(1L).build(), AccommodationRequest.builder() .checkinDate(LocalDate.now()) .checkoutDate(LocalDate.now().plusDays(2)) .build(), - DummyDataFactory.accommodationReservationInfoTypeSuiteRoomOnePersonTwoDays() + AccommodationReservationInfoDummyDataFactory.suiteRoomOnePersonTwoDays() ), Arguments.of( 1L, - DummyDataFactory.accommodationBuilderTypeSuiteRoom().id(1L).build(), + AccommodationDummyDataFactory.builderWithSuiteRoom().id(1L).build(), AccommodationRequest.builder() .build(), - DummyDataFactory.accommodationReservationInfoTypeSuiteRoomOnePersonOneDay() + AccommodationReservationInfoDummyDataFactory.suiteRoomOnePersonOneDay() ) ); } diff --git a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/reservation/controller/ReservationControllerTest.java b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/reservation/controller/ReservationControllerTest.java index 1b8d7e515..c6c18024a 100644 --- a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/reservation/controller/ReservationControllerTest.java +++ b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/reservation/controller/ReservationControllerTest.java @@ -1,6 +1,6 @@ package com.codesquad.airbnb.reservation.controller; -import com.codesquad.airbnb.common.utils.DummyDataFactory; +import com.codesquad.airbnb.common.dummydata.ReservationDTODummyDataFactory; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -54,7 +54,7 @@ static Stream readAllProvider() { Arguments.of( "/users/{userId}/reservations", 1L, - DummyDataFactory.reservations() + ReservationDTODummyDataFactory.list() ) ); } @@ -84,7 +84,7 @@ static Stream reservationProvider() { "/users/{userId}/reservations/{reservationId}", 1L, 1L, - DummyDataFactory.reservation() + ReservationDTODummyDataFactory.create() ) ); } diff --git a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/wishlist/WishlistControllerTest.java b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/wishlist/WishlistControllerTest.java index 0c47f96ef..bee135883 100644 --- a/BE/airbnb-be/src/test/java/com/codesquad/airbnb/wishlist/WishlistControllerTest.java +++ b/BE/airbnb-be/src/test/java/com/codesquad/airbnb/wishlist/WishlistControllerTest.java @@ -1,6 +1,6 @@ package com.codesquad.airbnb.wishlist; -import com.codesquad.airbnb.common.utils.DummyDataFactory; +import com.codesquad.airbnb.common.dummydata.WishlistItemDTODummyDataFactory; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; @@ -54,7 +54,7 @@ static Stream readAllProvider() { Arguments.of( "/users/{userId}/wishlist", 1L, - DummyDataFactory.wishlist() + WishlistItemDTODummyDataFactory.list() ) ); }