Skip to content

Commit

Permalink
#43 [feat] : 답변 요약 내역 조회 API 구현 (GET)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbbang105 committed May 19, 2024
1 parent f1b50af commit 9b189c8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,14 @@ public ResponseEntity<ApiResponse<DiscoverPersonaDto.ChattingResponse>> getChatt

return ApiResponse.onSuccess(PersonaSuccessStatus.GET_CHATTINGS, chattingResponse);
}

// 돌아보기 페르소나 답변 요약 내역을 조회하는 API
@GetMapping("/discover/summaries")
public ResponseEntity<ApiResponse<DiscoverPersonaDto.SummaryResponse>> getSummaries(
@RequestHeader("Authorization") String authorizationHeader) {

DiscoverPersonaDto.SummaryResponse summaryResponse = discoverPersonaService.getSummaries(authorizationHeader);

return ApiResponse.onSuccess(PersonaSuccessStatus.GET_SUMMARIES, summaryResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ public interface DiscoverPersonaService {
DiscoverPersonaDto.QuestionResponse getNewQuestion(String authorizationHeader, String category);
DiscoverPersonaDto.AnswerResponse getReactionAndSummary(String authorizationHeader, DiscoverPersonaDto.AnswerRequest answerRequest);
DiscoverPersonaDto.ChattingResponse getChattings(String authorizationHeader, String category);
DiscoverPersonaDto.SummaryResponse getSummaries(String authorizationHeader);
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,27 @@ public DiscoverPersonaDto.ChattingResponse getChattings(String authorizationHead
return DiscoverPersonaDto.ChattingResponse.of(stageQuestions, chattings);
}

// 답변 요약 내역을 반환하는 메서드
@Override
public DiscoverPersonaDto.SummaryResponse getSummaries(String authorizationHeader) {
String token = jwtUtil.getTokenFromHeader(authorizationHeader);
UUID userId = UUID.fromString(jwtUtil.getUserIdFromToken(token));
User user = userRepository.findByUserId(userId)
.orElseThrow(() -> new UserException(UserErrorResult.NOT_FOUND_USER));

DiscoverPersona healthDiscoverPersona = discoverPersonaRepository.findTopByUserAndCategoryOrderByCreateDateDesc(user, "건강");
DiscoverPersona careerDiscoverPersona = discoverPersonaRepository.findTopByUserAndCategoryOrderByCreateDateDesc(user, "커리어");
DiscoverPersona loveDiscoverPersona = discoverPersonaRepository.findTopByUserAndCategoryOrderByCreateDateDesc(user, "사랑");
DiscoverPersona leisureDiscoverPersona = discoverPersonaRepository.findTopByUserAndCategoryOrderByCreateDateDesc(user, "여가");

List<String> healthSummaries = createSummaries(healthDiscoverPersona);
List<String> careerSummaries = createSummaries(careerDiscoverPersona);
List<String> loveSummaries = createSummaries(loveDiscoverPersona);
List<String> leisureSummaries = createSummaries(leisureDiscoverPersona);

return DiscoverPersonaDto.SummaryResponse.of(healthSummaries, careerSummaries, loveSummaries, leisureSummaries);
}

// 질문 번호를 생성하는 메서드
private int createNewQuestionNumber(List<Integer> questionNumbers) {
int randomQuestionNumber = numberUtil.getRandomNumberNotInList(questionNumbers);
Expand Down Expand Up @@ -136,4 +157,15 @@ private List<String> createStageQuestions(String category, List<DiscoverPersonaC

return stageQuestions;
}

// 답변 요약 목록을 반환하는 메서드
private List<String> createSummaries(DiscoverPersona discoverPersona) {
List<DiscoverPersonaChatting> chattings = discoverPersonaChattingRepository.findAllByDiscoverPersonaOrderByCreatedDateAsc(discoverPersona);
List<String> summaries = new ArrayList<>();
for (DiscoverPersonaChatting discoverPersonaChatting : chattings) {
summaries.add(discoverPersonaChatting.getSummary());
}

return summaries;
}
}

0 comments on commit 9b189c8

Please sign in to comment.