Skip to content

Commit

Permalink
Merge pull request #79 from KUSITMS-29th-TEAM-D/feature/#74/final-ref…
Browse files Browse the repository at this point in the history
…actoring

[feat] : 키워드가 아예 존재하지 않는 경우 404 에러 처리 추가
  • Loading branch information
bbbang105 authored May 23, 2024
2 parents 0a24016 + 15450eb commit eb8c7bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import kusitms.jangkku.domain.persona.exception.PersonaException;
import kusitms.jangkku.domain.user.domain.User;
import kusitms.jangkku.global.util.JwtUtil;
import kusitms.jangkku.global.util.NumberUtil;
import kusitms.jangkku.global.util.StringUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -28,7 +27,6 @@
@RequiredArgsConstructor
public class DiscoverPersonaServiceImpl implements DiscoverPersonaService {
private final JwtUtil jwtUtil;
private final NumberUtil numberUtil;
private final StringUtil stringUtil;
private final ClovaService clovaService;
private final DiscoverPersonaRepository discoverPersonaRepository;
Expand Down Expand Up @@ -56,8 +54,8 @@ public DiscoverPersonaDto.QuestionResponse getNewQuestion(String authorizationHe
}

List<Integer> questionNumbers = discoverPersonaChattingRepository.findQuestionNumbersByDiscoverPersona(discoverPersona);
int newQuestionNumber = createNewQuestionNumber(questionNumbers);
if (questionNumbers.size() == 3) {
int newQuestionNumber = questionNumbers.size() + 1;
if (newQuestionNumber == 3) {
discoverPersona.updateComplete(true); // 완료 처리
discoverPersonaRepository.save(discoverPersona);
}
Expand All @@ -82,6 +80,10 @@ public DiscoverPersonaDto.AnswerResponse getReactionAndSummary(String authorizat
.orElseThrow(() -> new PersonaException(PersonaErrorResult.NOT_FOUND_CHATTING));

String reaction = clovaService.createDiscoverPersonaReaction(answerRequest.getAnswer());
// 마지막 대화인 경우 마무리 멘트 추가
if (discoverPersonaChatting.getDiscoverPersona().getIsComplete()) {
reaction += Question.FINAL_COMMENT.getContent();
}
String summary = clovaService.createDiscoverPersonaSummary(answerRequest.getAnswer());

discoverPersonaChatting.updateAnswer(answerRequest.getAnswer());
Expand Down Expand Up @@ -173,6 +175,9 @@ public DiscoverPersonaDto.KeywordResponse getAllKeywords(String authorizationHea
User user = jwtUtil.getUserFromHeader(authorizationHeader);

List<DiscoverPersonaKeyword> allKeywords = collectKeywords(user);
if (allKeywords.isEmpty()) {
throw new PersonaException(PersonaErrorResult.NOT_FOUND_ANY_KEYWORDS);
}

// 상위 6개 키워드만 반환
List<String> topKeywords = getTopKeywords(allKeywords);
Expand Down Expand Up @@ -243,13 +248,13 @@ private List<String> getTopKeywords(List<DiscoverPersonaKeyword> keywords) {
.collect(Collectors.toList());
}

// 질문 번호를 생성하는 메서드
/* 질문 번호를 생성하는 메서드
private int createNewQuestionNumber(List<Integer> questionNumbers) {
int randomQuestionNumber = numberUtil.getRandomNumberNotInList(questionNumbers);
questionNumbers.add(randomQuestionNumber);
return randomQuestionNumber;
}
} */

// Enum에서 질문 내용을 가져오는 메서드
private String getQuestionContent(String category, int number) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public enum PersonaErrorResult implements BaseErrorCode {
IS_ALREADY_COMPLETED(HttpStatus.CONFLICT, "409", "이미 답변이 종료된 카테고리입니다."),
NOT_FOUND_QUESTION(HttpStatus.NOT_FOUND, "404", "존재하지 않는 질문입니다."),
NOT_FOUND_CHATTING(HttpStatus.NOT_FOUND, "404", "존재하지 않는 채팅입니다."),
NOT_FOUND_ANY_KEYWORDS(HttpStatus.NOT_FOUND, "404", "테스트를 진행하지 않아 키워드가 존재하지 않습니다."),
NOT_FOUND_KEYWORDS(HttpStatus.NOT_FOUND, "404", "대화가 완료되지 않아 키워드가 존재하지 않습니다.");

private final HttpStatus httpStatus;
Expand Down

0 comments on commit eb8c7bc

Please sign in to comment.