Skip to content

Commit

Permalink
Merge pull request #401 from softeerbootcamp-2nd/dev
Browse files Browse the repository at this point in the history
MAIN MERGE
  • Loading branch information
tank3a authored Aug 22, 2023
2 parents 94d9b93 + 71266a9 commit 7938ed4
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ public class QuoteController {
@ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = HistoryShortDto.class)))
})
@PostMapping("/list")
public List<HistoryShortDto> getRecommendedList(@RequestBody QuoteDataDto quoteDataDto) {
List<HistoryShortDto> result = quoteService.findTopHistory(quoteDataDto);
return result;
public HistoryShortDto getRecommendedList(@RequestBody QuoteDataDto quoteDataDto) {
HistoryShortDto myQuote = quoteService.findMyQuote(quoteDataDto);
List<HistoryShortDto> subList = quoteService.findTopHistory(quoteDataDto);

myQuote.setHistories(subList);

return myQuote;
}

@Operation(summary = "차량 구매 정보 반환 api", description = "차량 구매 정보 조회 method")
Expand Down
13 changes: 13 additions & 0 deletions backend/src/main/java/autoever2/cartag/service/QuoteService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ public class QuoteService {
private final QuoteRepository quoteRepository;
private final RecommendConnector recommendConnector;

public HistoryShortDto findMyQuote(QuoteDataDto quoteDataDto) {
List<Integer> 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<HistoryShortDto> findTopHistory(QuoteDataDto quoteDataDto) {

List<Integer> optionIds = quoteDataDto.getOptionIdList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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에 따른 공유 데이터 반환")
Expand Down

0 comments on commit 7938ed4

Please sign in to comment.