diff --git a/backend/src/main/java/autoever2/cartag/controller/QuoteController.java b/backend/src/main/java/autoever2/cartag/controller/QuoteController.java index 8ab4177..954ad33 100644 --- a/backend/src/main/java/autoever2/cartag/controller/QuoteController.java +++ b/backend/src/main/java/autoever2/cartag/controller/QuoteController.java @@ -30,9 +30,13 @@ public class QuoteController { @ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = HistoryShortDto.class))) }) @PostMapping("/list") - public List getRecommendedList(@RequestBody QuoteDataDto quoteDataDto) { - List result = quoteService.findTopHistory(quoteDataDto); - return result; + public HistoryShortDto getRecommendedList(@RequestBody QuoteDataDto quoteDataDto) { + HistoryShortDto myQuote = quoteService.findMyQuote(quoteDataDto); + List subList = quoteService.findTopHistory(quoteDataDto); + + myQuote.setHistories(subList); + + return myQuote; } @Operation(summary = "차량 구매 정보 반환 api", description = "차량 구매 정보 조회 method") diff --git a/backend/src/main/java/autoever2/cartag/service/QuoteService.java b/backend/src/main/java/autoever2/cartag/service/QuoteService.java index 585fe5e..1155179 100644 --- a/backend/src/main/java/autoever2/cartag/service/QuoteService.java +++ b/backend/src/main/java/autoever2/cartag/service/QuoteService.java @@ -22,6 +22,19 @@ public class QuoteService { private final QuoteRepository quoteRepository; private final RecommendConnector recommendConnector; + public HistoryShortDto findMyQuote(QuoteDataDto quoteDataDto) { + List optionIds = quoteDataDto.getOptionIdList(); + + HistorySearchDto historyData = HistorySearchDto.builder() + .carId(quoteDataDto.getCarId()) + .powerTrainId(quoteDataDto.getPowerTrainId()) + .bodyTypeId(quoteDataDto.getBodyTypeId()) + .operationId(quoteDataDto.getOperationId()) + .optionIds(optionIds) + .build(); + return quoteRepository.findShortData(historyData).orElse(HistoryShortDto.builder().build()); + } + public List findTopHistory(QuoteDataDto quoteDataDto) { List optionIds = quoteDataDto.getOptionIdList(); diff --git a/backend/src/test/java/autoever2/cartag/controller/QuoteControllerTest.java b/backend/src/test/java/autoever2/cartag/controller/QuoteControllerTest.java index 7c3c285..c0d23c0 100644 --- a/backend/src/test/java/autoever2/cartag/controller/QuoteControllerTest.java +++ b/backend/src/test/java/autoever2/cartag/controller/QuoteControllerTest.java @@ -69,18 +69,26 @@ void getRecommendedList() throws Exception { .soldCount(140) .build()); + HistoryShortDto myQuote = HistoryShortDto.builder() + .historyId(123L) + .soldCount(110) + .build(); + String content = objectMapper.writeValueAsString(quoteDataDto); given(quoteService.findTopHistory(quoteDataDto)).willReturn(expected); + given(quoteService.findMyQuote(quoteDataDto)).willReturn(myQuote); //when ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.post("/api/quote/list").content(content) .contentType(MediaType.APPLICATION_JSON)); //then resultActions.andExpect(status().isOk()) - .andExpect(jsonPath("$[0].historyId").value(129)) - .andExpect(jsonPath("$[1].soldCount").value(140)) - .andExpect(jsonPath("$[2].soldCount").value(162)) - .andExpect(jsonPath("$[3].historyId").value(169)); + .andExpect(jsonPath("$.historyId").value(123L)) + .andExpect(jsonPath("$.soldCount").value(110)) + .andExpect(jsonPath("$.histories[0].historyId").value(129)) + .andExpect(jsonPath("$.histories[1].soldCount").value(140)) + .andExpect(jsonPath("$.histories[2].soldCount").value(162)) + .andExpect(jsonPath("$.histories[3].historyId").value(169)); } @Test @DisplayName("id에 따른 공유 데이터 반환")