diff --git a/pickle-common/src/main/java/com/example/pickle_common/strategy/dto/ReadStrategyResponseDto.java b/pickle-common/src/main/java/com/example/pickle_common/strategy/dto/ReadStrategyResponseDto.java index 9937dab..671f108 100644 --- a/pickle-common/src/main/java/com/example/pickle_common/strategy/dto/ReadStrategyResponseDto.java +++ b/pickle-common/src/main/java/com/example/pickle_common/strategy/dto/ReadStrategyResponseDto.java @@ -23,10 +23,32 @@ public class ReadStrategyResponseDto { @AllArgsConstructor @NoArgsConstructor public static class StrategyInfoDto { + private int id; private String name; private String pbName; private String pbBranchOffice; private LocalDateTime createdAt; - private List categoryComposition; + private List categoryList; } + + @Builder + @AllArgsConstructor + @Getter + @NoArgsConstructor + public static class CategoryDto { + private String categoryName; + private double categoryRatio; + private List productList; + } + + @Getter + @AllArgsConstructor + @Builder + @NoArgsConstructor + public static class ProductDto { + private String code; + private String name; + private String themeName; + private double ratio; + } } diff --git a/pickle-common/src/main/java/com/example/pickle_common/strategy/service/StrategyService.java b/pickle-common/src/main/java/com/example/pickle_common/strategy/service/StrategyService.java index c87e73b..91c65c9 100644 --- a/pickle-common/src/main/java/com/example/pickle_common/strategy/service/StrategyService.java +++ b/pickle-common/src/main/java/com/example/pickle_common/strategy/service/StrategyService.java @@ -19,6 +19,7 @@ import com.example.real_common.stockEnum.ThemeEnum; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; +import org.springframework.beans.factory.annotation.Value; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.web.client.RestClient; @@ -36,6 +37,9 @@ public class StrategyService { private final ConsultingHistoryRepository consultingHistoryRepository; private final MessageQueueService messageQueueService; + @Value("${PICKLE_PB_URL}") + private String PICKLE_PB_URL; + @Transactional public CreateStrategyResponseDto postStrategy(CreateStrategyRequestDto requestDto, String authorizationHeader) { @@ -98,28 +102,33 @@ public CreateStrategyResponseDto postStrategy(CreateStrategyRequestDto requestDt public ReadStrategyResponseDto readStrategy(String authorizationHeader) { int customerId = messageQueueService.getCustomerIdByCustomerToken(authorizationHeader); +// int customerId = 1; + if (customerId == -1) { + throw new NotFoundAccountException("not found user account, customerId : " + customerId); + } List existStrategies = strategyRepository.findAllByCustomerId(customerId); - RestClient restClient = CustomRestClient.connectPb("/inner"); + RestClient restClient = CustomRestClient.connectPb(PICKLE_PB_URL); List strategyList = existStrategies.stream() .map(existStrategy -> { + int curpbId = existStrategy.getPbId(); RestClientDto.PbInfoRequestDto pbInfo = restClient.get() - .uri("/{pbId}", existStrategy.getPbId()) + .uri("/api/pickle-pb/inner/{curpbId}", curpbId) .accept(MediaType.APPLICATION_JSON) .retrieve() .body(RestClientDto.PbInfoRequestDto.class); - List curCategoryComposition = categoryCompositionRepository.findByStrategy_strategyId(existStrategy.getStrategyId()).stream() - .map(CategoryComposition::getCategoryName).toList(); + List categoryDtoList = getCategoryDtoList(existStrategy.getStrategyId()); return ReadStrategyResponseDto.StrategyInfoDto.builder() + .id(existStrategy.getStrategyId()) .name(existStrategy.getName()) .pbName(pbInfo.getName()) .pbBranchOffice(pbInfo.getBranchOffice()) .createdAt(existStrategy.getCreatedAt()) - .categoryComposition(curCategoryComposition) + .categoryList(categoryDtoList) .build(); }).toList(); diff --git a/real-common/src/main/java/com/example/real_common/global/restClient/CustomRestClient.java b/real-common/src/main/java/com/example/real_common/global/restClient/CustomRestClient.java index 5360f73..dedfa95 100644 --- a/real-common/src/main/java/com/example/real_common/global/restClient/CustomRestClient.java +++ b/real-common/src/main/java/com/example/real_common/global/restClient/CustomRestClient.java @@ -8,7 +8,7 @@ public class CustomRestClient { public static RestClient connectPb(String path) { return RestClient.builder() - .baseUrl(baseUrl + ":8002/api/pickle-pb" + path) + .baseUrl(path) .build(); }