Skip to content

Commit

Permalink
store client 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
f-lab-lion committed Sep 11, 2023
1 parent 0c990f9 commit 9df585e
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 91 deletions.
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();
}
}
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;
}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.ch.yourdelivery.store.util;
package com.ch.yourdelivery.external.util;

import com.ch.yourdelivery.store.domain.model.DeliveryLocation;
import com.ch.yourdelivery.store.domain.model.OperatingTimeInMonth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
import com.ch.yourdelivery.store.service.StoreService;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -15,7 +15,7 @@ public class StoreController {

//가게정보 다건조회
@GetMapping("/stores")
public List<StoreResponse> findStores() {
public List<StoreResponse> findStores(@RequestParam String category, Pageable pageable) {
return storeService.findAllStores();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
@Builder
public class Menu {

private long id; // 메뉴 id
private String name; // 메뉴 이름
private int price; // 가격
private String imagePath; // 이미지 경로
Expand Down
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();
}
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();
}

}

This file was deleted.

0 comments on commit 9df585e

Please sign in to comment.