Skip to content

Commit

Permalink
refactor: 더미데이터 팩토리 각 타입별로 분리
Browse files Browse the repository at this point in the history
너무 많아져서 관리가 힘들어짐.
  • Loading branch information
Dae-Hwa committed May 31, 2021
1 parent 4eae755 commit 3cf2ad9
Show file tree
Hide file tree
Showing 19 changed files with 329 additions and 249 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -31,7 +30,7 @@ public AccommodationDTO readOne(@PathVariable long id) {

@GetMapping("/accommodationPriceStats")
public List<AccommodationPriceStats> priceStats() {
return DummyDataFactory.accommodationPriceStats();
return AccommodationPriceStatsDummyDataFactory.list();
}

@GetMapping("/accommodations/{id}/reservation")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

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;

@Repository
public class AccommodationRepository {
public List<Accommodation> 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -16,7 +18,7 @@
@Profile("mockup")
public class AccommodationServiceMockup implements AccommodationService {
public List<AccommodationResponse> readAll(AccommodationRequest accommodationRequest) {
List<AccommodationResponse> result = DummyDataFactory.accommodationResponseDTOsWithIdTypeOneNight();
List<AccommodationResponse> result = AccommodationResponseDummyDataFactory.listWithIdTypeOneNight();

if (accommodationRequest.getStartPrice() != null) {
result = result.stream()
Expand All @@ -34,7 +36,7 @@ public List<AccommodationResponse> readAll(AccommodationRequest accommodationReq
}

public AccommodationDTO readOne(long id) {
List<AccommodationDTO> result = DummyDataFactory.accommodationDTOsWithId();
List<AccommodationDTO> result = AccommodationDTODummyDataFactory.listWithId();

return result.stream()
.filter(accommodationDTO -> accommodationDTO.getId() == id)
Expand All @@ -44,6 +46,6 @@ public AccommodationDTO readOne(long id) {

@Override
public AccommodationReservationInfo accommodationReservationInfo(long id, AccommodationRequest accommodationRequest) {
return DummyDataFactory.accommodationReservationInfoTypeSuiteRoomOnePersonOneDay();
return AccommodationReservationInfoDummyDataFactory.suiteRoomOnePersonOneDay();
}
}
Original file line number Diff line number Diff line change
@@ -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<AccommodationDTO> listWithId() {
return AccommodationDummyDataFactory.listWithId().stream()
.map(AccommodationDTO::from)
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -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<Accommodation> list() {
return Arrays.asList(
builderWithSuiteRoom().build(),
builderWithOneRoom().build(),
builderWithLowQuality().build()
);
}

public static List<Accommodation> listWithId() {
return Arrays.asList(
builderWithSuiteRoom().id(1L).build(),
builderWithOneRoom().id(2L).build(),
builderWithLowQuality().id(3L).build()
);
}
}
Original file line number Diff line number Diff line change
@@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<AccommodationPriceStats> list() {
return Arrays.asList(
new AccommodationPriceStats(10000, 10),
new AccommodationPriceStats(30000, 11),
new AccommodationPriceStats(20000, 21)
);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<AccommodationResponse> listWithOneNight() {
return AccommodationDummyDataFactory.list().stream()
.map(accommodation -> AccommodationResponse.of(accommodation,1))
.collect(Collectors.toList());
}

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

public static List<AccommodationResponse> listWithIdTypeTwoNights() {
return AccommodationDummyDataFactory.listWithId().stream()
.map(accommodation -> AccommodationResponse.of(accommodation,2))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
@@ -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<ReservationDTO> list() {
return Arrays.asList(create(), create());
}

public static ReservationDTO create() {
return new ReservationDTO(1L, AccommodationResponse.from(AccommodationDummyDataFactory.builderWithSuiteRoom().build()));
}
}
Original file line number Diff line number Diff line change
@@ -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<WishlistItemDTO> list() {
return Arrays.asList(create(), create());
}

public static WishlistItemDTO create() {
return new WishlistItemDTO(1L, AccommodationResponse.from(AccommodationDummyDataFactory.builderWithSuiteRoom().build()));
}
}
Loading

0 comments on commit 3cf2ad9

Please sign in to comment.