From 8b54c15eb6e78e96dcfdb8382c0a245ac9b2c9bb Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 20 May 2024 03:33:44 +0900 Subject: [PATCH 1/7] =?UTF-8?q?#43=20[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=82=B4=EC=97=AD=20=EC=A1=B0=ED=9A=8C=20=EC=84=B1=EA=B3=B5=20?= =?UTF-8?q?Enum=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jangkku/domain/persona/constant/PersonaSuccessStatus.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java b/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java index f0acb80..4377a03 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java +++ b/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java @@ -12,12 +12,13 @@ public enum PersonaSuccessStatus implements BaseCode { // 돌아보기 페르소나 CREATED_NEW_QUESTION(HttpStatus.CREATED, "201", "돌아보기 페르소나 질문 생성에 성공했습니다."), CREATED_REACTION_AND_SUMMARY(HttpStatus.CREATED, "201", "돌아보기 페르소나 공감 & 요약 생성에 성공했습니다."), + GET_CHATTINGS(HttpStatus.CREATED, "200", "채팅 내역 조회에 성공했습니다."), // 정의하기 페르소나 CREATED_DEFINE_PERSONA(HttpStatus.CREATED, "201", "정의하기 페르소나 생성에 성공했습니다."), GET_DEFINE_PERSONA(HttpStatus.OK, "200", "정의하기 페르소나 조회에 성공했습니다."), // 설계하기 페르소나 CREATED_DESIGN_PERSONA(HttpStatus.CREATED, "201", "설계하기 페르소나 생성에 성공했습니다."), - GET_DESIGN_PERSONA(HttpStatus.CREATED, "200", "설계하기 페르소나 조회에 성공했습니다."); + GET_DESIGN_PERSONA(HttpStatus.OK, "200", "설계하기 페르소나 조회에 성공했습니다."); private final HttpStatus httpStatus; private final String code; From 688fafdce405dc2bf8b0e64a37821ed728fd1f6c Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 20 May 2024 03:34:13 +0900 Subject: [PATCH 2/7] =?UTF-8?q?#43=20[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=82=B4=EC=97=AD=20DTO=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../persona/dto/DiscoverPersonaDto.java | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java b/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java index e079ce8..d0050ae 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java +++ b/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java @@ -3,11 +3,14 @@ import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.databind.PropertyNamingStrategies; import com.fasterxml.jackson.databind.annotation.JsonNaming; +import kusitms.jangkku.domain.persona.domain.DiscoverPersonaChatting; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + public class DiscoverPersonaDto { @Builder @Getter @@ -58,4 +61,44 @@ public static DiscoverPersonaDto.AnswerResponse of(String reaction, String summa .build(); } } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + @JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class ChattingResponse { + private Stage stageOne; + private Stage stageTwo; + private Stage stageThree; + + public static ChattingResponse of(List questions, List chattings) { + return ChattingResponse.builder() + .stageOne(Stage.of(questions.get(0), chattings.get(0).getAnswer(), chattings.get(0).getReaction())) + .stageTwo(questions.size() > 1 && chattings.size() > 1 ? Stage.of(questions.get(1), chattings.get(1).getAnswer(), chattings.get(1).getReaction()) : null) + .stageThree(questions.size() > 2 && chattings.size() > 2 ? Stage.of(questions.get(2), chattings.get(2).getAnswer(), chattings.get(2).getReaction()) : null) + .build(); + } + } + + @Builder + @Getter + @NoArgsConstructor + @AllArgsConstructor + @JsonNaming(value = PropertyNamingStrategies.SnakeCaseStrategy.class) + @JsonInclude(JsonInclude.Include.NON_NULL) + public static class Stage { + private String question; + private String answer; + private String reaction; + + public static DiscoverPersonaDto.Stage of(String question, String answer, String reaction) { + return DiscoverPersonaDto.Stage.builder() + .question(question) + .answer(answer) + .reaction(reaction) + .build(); + } + } } \ No newline at end of file From 31b80999c62f98e6e4c7f71d5a3e8e9e0ab77891 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 20 May 2024 03:35:11 +0900 Subject: [PATCH 3/7] =?UTF-8?q?#43=20[feat]=20:=20=EC=9C=A0=EC=A0=80?= =?UTF-8?q?=EC=99=80=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=EB=A1=9C=20?= =?UTF-8?q?=EC=B0=BE=EB=8A=94=20=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jangkku/domain/persona/dao/DiscoverPersonaRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaRepository.java b/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaRepository.java index f82e33e..b1a0cbd 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaRepository.java +++ b/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaRepository.java @@ -10,4 +10,5 @@ public interface DiscoverPersonaRepository extends JpaRepository Date: Mon, 20 May 2024 03:37:23 +0900 Subject: [PATCH 4/7] =?UTF-8?q?#43=20[feat]=20:=20=EC=8B=9C=EA=B0=84?= =?UTF-8?q?=EC=88=9C=EC=9C=BC=EB=A1=9C=20=EC=B1=84=ED=8C=85=20=EB=82=B4?= =?UTF-8?q?=EC=97=AD=EC=9D=84=20=EA=B0=80=EC=A0=B8=EC=98=A4=EB=8A=94=20?= =?UTF-8?q?=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/persona/dao/DiscoverPersonaChattingRepository.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaChattingRepository.java b/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaChattingRepository.java index 17b24a3..bc99766 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaChattingRepository.java +++ b/src/main/java/kusitms/jangkku/domain/persona/dao/DiscoverPersonaChattingRepository.java @@ -10,4 +10,5 @@ public interface DiscoverPersonaChattingRepository extends JpaRepository { @Query("SELECT dc.questionNumber FROM DiscoverPersonaChatting dc WHERE dc.discoverPersona = :discoverPersona") List findQuestionNumbersByDiscoverPersona(DiscoverPersona discoverPersona); + List findAllByDiscoverPersonaOrderByCreatedDateAsc(DiscoverPersona discoverPersona); } \ No newline at end of file From 1ce07ebf458e1e6a55b95011f03b1de545a865e5 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 20 May 2024 03:37:49 +0900 Subject: [PATCH 5/7] =?UTF-8?q?#43=20[feat]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=82=B4=EC=97=AD=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84=20(GET)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/DiscoverPersonaController.java | 11 ++++++++ .../application/DiscoverPersonaService.java | 1 + .../DiscoverPersonaServiceImpl.java | 27 ++++++++++++++++++- 3 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/main/java/kusitms/jangkku/domain/persona/api/DiscoverPersonaController.java b/src/main/java/kusitms/jangkku/domain/persona/api/DiscoverPersonaController.java index c82346a..17d8cf3 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/api/DiscoverPersonaController.java +++ b/src/main/java/kusitms/jangkku/domain/persona/api/DiscoverPersonaController.java @@ -35,4 +35,15 @@ public ResponseEntity> getReactio return ApiResponse.onSuccess(PersonaSuccessStatus.CREATED_REACTION_AND_SUMMARY, answerResponse); } + + // 돌아보기 페르소나 카테고리별 채팅 내역을 조회하는 API + @GetMapping("/discover/chattings") + public ResponseEntity> getChattings( + @RequestHeader("Authorization") String authorizationHeader, + @RequestParam("category") String category) { + + DiscoverPersonaDto.ChattingResponse chattingResponse = discoverPersonaService.getChattings(authorizationHeader, category); + + return ApiResponse.onSuccess(PersonaSuccessStatus.GET_CHATTINGS, chattingResponse); + } } \ No newline at end of file diff --git a/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaService.java b/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaService.java index 5dad9ef..faf0cfd 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaService.java +++ b/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaService.java @@ -5,4 +5,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); } \ No newline at end of file diff --git a/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java b/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java index e69e4d6..8c1cf59 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java +++ b/src/main/java/kusitms/jangkku/domain/persona/application/DiscoverPersonaServiceImpl.java @@ -18,6 +18,7 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import java.util.ArrayList; import java.util.List; import java.util.UUID; @@ -92,6 +93,21 @@ public DiscoverPersonaDto.AnswerResponse getReactionAndSummary(String authorizat return DiscoverPersonaDto.AnswerResponse.of(reaction, summary); } + // 카테고리별 채팅 내역을 반환하는 메서드 + @Override + public DiscoverPersonaDto.ChattingResponse getChattings(String authorizationHeader, String category) { + 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 discoverPersona = discoverPersonaRepository.findByUserAndCategory(user, category); + List chattings = discoverPersonaChattingRepository.findAllByDiscoverPersonaOrderByCreatedDateAsc(discoverPersona); + List stageQuestions = createStageQuestions(category, chattings); + + return DiscoverPersonaDto.ChattingResponse.of(stageQuestions, chattings); + } + // 질문 번호를 생성하는 메서드 private int createNewQuestionNumber(List questionNumbers) { int randomQuestionNumber = numberUtil.getRandomNumberNotInList(questionNumbers); @@ -102,7 +118,6 @@ private int createNewQuestionNumber(List questionNumbers) { // Enum에서 질문 내용을 가져오는 메서드 private String getQuestionContent(String category, int number) { - // Question Enum에서 category와 number에 해당하는 content 찾기 for (Question question : Question.values()) { if (question.getCategory().equals(category) && question.getNumber() == number) { return question.getContent(); @@ -111,4 +126,14 @@ private String getQuestionContent(String category, int number) { throw new PersonaException(PersonaErrorResult.NOT_FOUND_QUESTION); } + + // 질문 목록을 생성하는 메서드 + private List createStageQuestions(String category, List chattings) { + List stageQuestions = new ArrayList<>(); + for (DiscoverPersonaChatting discoverPersonaChatting : chattings) { + stageQuestions.add(getQuestionContent(category, discoverPersonaChatting.getQuestionNumber())); + } + + return stageQuestions; + } } \ No newline at end of file From bba99585e51c206187828f439f1033f29a85ef38 Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 20 May 2024 03:39:22 +0900 Subject: [PATCH 6/7] =?UTF-8?q?#43=20[fix]=20:=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=82=B4=EC=97=AD=EC=9D=B4=20=EC=97=86=EC=9D=84=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EA=B3=A0=EB=A0=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java b/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java index d0050ae..1ca68d8 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java +++ b/src/main/java/kusitms/jangkku/domain/persona/dto/DiscoverPersonaDto.java @@ -75,7 +75,7 @@ public static class ChattingResponse { public static ChattingResponse of(List questions, List chattings) { return ChattingResponse.builder() - .stageOne(Stage.of(questions.get(0), chattings.get(0).getAnswer(), chattings.get(0).getReaction())) + .stageOne(!questions.isEmpty() && !chattings.isEmpty() ? Stage.of(questions.get(0), chattings.get(0).getAnswer(), chattings.get(0).getReaction()) : null) .stageTwo(questions.size() > 1 && chattings.size() > 1 ? Stage.of(questions.get(1), chattings.get(1).getAnswer(), chattings.get(1).getReaction()) : null) .stageThree(questions.size() > 2 && chattings.size() > 2 ? Stage.of(questions.get(2), chattings.get(2).getAnswer(), chattings.get(2).getReaction()) : null) .build(); From 9727d0958316228c544119bab8e7fb98518f89ed Mon Sep 17 00:00:00 2001 From: bbbang105 <2018111366@dgu.ac.kr> Date: Mon, 20 May 2024 03:39:46 +0900 Subject: [PATCH 7/7] =?UTF-8?q?#43=20[style]=20:=20HTTP=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EC=BD=94=EB=93=9C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jangkku/domain/persona/constant/PersonaSuccessStatus.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java b/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java index 4377a03..da8ea22 100644 --- a/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java +++ b/src/main/java/kusitms/jangkku/domain/persona/constant/PersonaSuccessStatus.java @@ -12,7 +12,7 @@ public enum PersonaSuccessStatus implements BaseCode { // 돌아보기 페르소나 CREATED_NEW_QUESTION(HttpStatus.CREATED, "201", "돌아보기 페르소나 질문 생성에 성공했습니다."), CREATED_REACTION_AND_SUMMARY(HttpStatus.CREATED, "201", "돌아보기 페르소나 공감 & 요약 생성에 성공했습니다."), - GET_CHATTINGS(HttpStatus.CREATED, "200", "채팅 내역 조회에 성공했습니다."), + GET_CHATTINGS(HttpStatus.OK, "200", "채팅 내역 조회에 성공했습니다."), // 정의하기 페르소나 CREATED_DEFINE_PERSONA(HttpStatus.CREATED, "201", "정의하기 페르소나 생성에 성공했습니다."), GET_DEFINE_PERSONA(HttpStatus.OK, "200", "정의하기 페르소나 조회에 성공했습니다."),