Skip to content

Commit

Permalink
Merge pull request #65 from PizzaPickle/refactor/read-strategy
Browse files Browse the repository at this point in the history
refactor: 전략 리스트 조회, 상세조회 같이 하도록 수정
  • Loading branch information
sooyeon-kr authored Sep 11, 2024
2 parents 9b504d8 + f8a2864 commit 6215f40
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> categoryComposition;
private List<ReadDetailStrategyResponseDto.CategoryDto> categoryList;
}

@Builder
@AllArgsConstructor
@Getter
@NoArgsConstructor
public static class CategoryDto {
private String categoryName;
private double categoryRatio;
private List<ReadDetailStrategyResponseDto.ProductDto> productList;
}

@Getter
@AllArgsConstructor
@Builder
@NoArgsConstructor
public static class ProductDto {
private String code;
private String name;
private String themeName;
private double ratio;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {

Expand Down Expand Up @@ -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<Strategy> existStrategies = strategyRepository.findAllByCustomerId(customerId);

RestClient restClient = CustomRestClient.connectPb("/inner");
RestClient restClient = CustomRestClient.connectPb(PICKLE_PB_URL);

List<ReadStrategyResponseDto.StrategyInfoDto> 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<String> curCategoryComposition = categoryCompositionRepository.findByStrategy_strategyId(existStrategy.getStrategyId()).stream()
.map(CategoryComposition::getCategoryName).toList();
List<ReadDetailStrategyResponseDto.CategoryDto> 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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down

0 comments on commit 6215f40

Please sign in to comment.