-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0c990f9
commit 9df585e
Showing
8 changed files
with
115 additions
and
91 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
your-delivery/src/main/java/com/ch/yourdelivery/external/MenuRandomSampleData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.ch.yourdelivery.external; | ||
|
||
import com.ch.yourdelivery.store.domain.model.Menu; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
import java.util.Random; | ||
import java.util.UUID; | ||
import java.util.stream.IntStream; | ||
|
||
|
||
public class MenuRandomSampleData { | ||
private static final Random random = new Random(); | ||
|
||
public static Menu generateRandomMenu() { | ||
|
||
return Menu.builder() | ||
.id(random.nextLong()) | ||
.name(UUID.randomUUID().toString()) | ||
.price(random.nextInt()%10000) | ||
.reviewScore(random.nextInt()%5) | ||
.deliveryTip(random.nextInt()%5000) | ||
.build(); | ||
} | ||
|
||
|
||
public static List<Menu> generateRandomMenus(Integer count) { | ||
return IntStream.range(0, count) | ||
.mapToObj(i -> generateRandomMenu()) | ||
.toList(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
your-delivery/src/main/java/com/ch/yourdelivery/external/StoreClientImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package com.ch.yourdelivery.external; | ||
|
||
import com.ch.yourdelivery.store.domain.dto.StoreResponse; | ||
import com.ch.yourdelivery.store.domain.model.DeliveryLocation; | ||
import com.ch.yourdelivery.store.domain.model.Menu; | ||
import com.ch.yourdelivery.store.domain.model.OperatingTimeInMonth; | ||
import com.ch.yourdelivery.store.service.StoreClient; | ||
import com.ch.yourdelivery.external.util.StoreRandomSampleData; | ||
import jakarta.annotation.PostConstruct; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Service | ||
public class StoreClientImpl implements StoreClient { | ||
|
||
public static final String CHICKEN = "치킨"; | ||
|
||
private List<StoreResponse> storeResponseList = new ArrayList<>(); | ||
private List<OperatingTimeInMonth> operatingTimeInMonthList = new ArrayList<>(); | ||
private List<DeliveryLocation> deliveryLocationList = new ArrayList<>(); | ||
|
||
@PostConstruct | ||
public void init(){ | ||
operatingTimeInMonthList.add(StoreRandomSampleData.generateOperatingTimeInMonth()); | ||
operatingTimeInMonthList.add(StoreRandomSampleData.generateOperatingTimeInMonth()); | ||
|
||
deliveryLocationList.add(StoreRandomSampleData.generateDeliveryLocation()); | ||
deliveryLocationList.add(StoreRandomSampleData.generateDeliveryLocation()); | ||
|
||
for (int i = 0; i < Math.random() * 10; i++) { | ||
String storeName = StoreRandomSampleData.generateStoreName(); | ||
|
||
StoreResponse storeResponse = StoreResponse.builder() | ||
.id(StoreRandomSampleData.generateRandomId()) | ||
.ownerId(StoreRandomSampleData.generateOwnerIndex()) | ||
.name(storeName) | ||
.operatingTimeList(operatingTimeInMonthList) | ||
.phoneNumber(StoreRandomSampleData.generatePhoneNumber()) | ||
.deliveryLocation(deliveryLocationList) | ||
.descriptionForNotification(StoreRandomSampleData.generateDescription()) | ||
.storeLocationXY(StoreRandomSampleData.generateStoreLocationXY()) | ||
.menus(MenuRandomSampleData.generateRandomMenus(5)) | ||
.build(); | ||
|
||
storeResponseList.add(storeResponse); | ||
} | ||
} | ||
|
||
@Override | ||
public List<StoreResponse> findAllStores() { | ||
//size 5 | ||
//page 3 | ||
// 11 = size * (page-1) + 1 | ||
// 15 = size * page | ||
//validation 해야함... | ||
//return storeResponseList.subList(size * (page-1) + 1, size * page); | ||
return storeResponseList; | ||
} | ||
|
||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ery/store/util/StoreRandomSampleData.java → .../external/util/StoreRandomSampleData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
your-delivery/src/main/java/com/ch/yourdelivery/store/service/StoreClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.ch.yourdelivery.store.service; | ||
|
||
import com.ch.yourdelivery.store.domain.dto.StoreResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface StoreClient { | ||
List<StoreResponse> findAllStores(); | ||
} |
59 changes: 6 additions & 53 deletions
59
your-delivery/src/main/java/com/ch/yourdelivery/store/service/StoreService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,19 @@ | ||
package com.ch.yourdelivery.store.service; | ||
|
||
import com.ch.yourdelivery.store.domain.dto.StoreResponse; | ||
import com.ch.yourdelivery.store.domain.model.DeliveryLocation; | ||
import com.ch.yourdelivery.store.domain.model.Menu; | ||
import com.ch.yourdelivery.store.domain.model.OperatingTimeInMonth; | ||
import com.ch.yourdelivery.store.util.MenuRandomSampleData; | ||
import com.ch.yourdelivery.store.util.StoreRandomSampleData; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class StoreService { | ||
|
||
public static final String CHICKEN = "치킨"; | ||
private final StoreClient storeClient; | ||
|
||
// StoreResponse list 를 반환해주는 함수 작성예정 | ||
// 다른 Interface 에서 가져온 데이터로 가정(ex. API, Interface) | ||
public List<StoreResponse> findAllStores() { | ||
|
||
List<StoreResponse> storeResponseList = new ArrayList<>(); | ||
List<OperatingTimeInMonth> operatingTimeInMonthList = new ArrayList<>(); | ||
List<DeliveryLocation> deliveryLocationList = new ArrayList<>(); | ||
|
||
operatingTimeInMonthList.add(StoreRandomSampleData.generateOperatingTimeInMonth()); | ||
operatingTimeInMonthList.add(StoreRandomSampleData.generateOperatingTimeInMonth()); | ||
|
||
deliveryLocationList.add(StoreRandomSampleData.generateDeliveryLocation()); | ||
deliveryLocationList.add(StoreRandomSampleData.generateDeliveryLocation()); | ||
|
||
for (int i = 0; i < Math.random() * 10; i++) { | ||
String storeName = StoreRandomSampleData.generateStoreName(); | ||
|
||
StoreResponse storeResponse = StoreResponse.builder() | ||
.id(StoreRandomSampleData.generateRandomId()) | ||
.ownerId(StoreRandomSampleData.generateOwnerIndex()) | ||
.name(storeName) | ||
.operatingTimeList(operatingTimeInMonthList) | ||
.phoneNumber(StoreRandomSampleData.generatePhoneNumber()) | ||
.deliveryLocation(deliveryLocationList) | ||
.descriptionForNotification(StoreRandomSampleData.generateDescription()) | ||
.storeLocationXY(StoreRandomSampleData.generateStoreLocationXY()) | ||
.menus(generateMenus(storeName)) | ||
.build(); | ||
|
||
storeResponseList.add(storeResponse); | ||
} | ||
|
||
return storeResponseList; | ||
} | ||
|
||
private List<Menu> generateMenus(String storeName) { | ||
|
||
List<Menu> menus = new ArrayList<>(); | ||
if (storeName.contains(CHICKEN)) { | ||
menus.add(MenuRandomSampleData.generateChickenMenu()); | ||
menus.add(MenuRandomSampleData.generateChickenMenu()); | ||
} else{ | ||
menus.add(MenuRandomSampleData.generateTteokbokkiMenu()); | ||
menus.add(MenuRandomSampleData.generateTteokbokkiMenu()); | ||
} | ||
return menus; | ||
return storeClient.findAllStores(); | ||
} | ||
|
||
} |
34 changes: 0 additions & 34 deletions
34
your-delivery/src/main/java/com/ch/yourdelivery/store/util/MenuRandomSampleData.java
This file was deleted.
Oops, something went wrong.