From d33bb4c6cebaa4bfc22363b2c0d085f24707ccbd Mon Sep 17 00:00:00 2001 From: minwoo0419 Date: Mon, 26 Aug 2024 20:24:32 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[fix]=20#124=20=EB=9E=9C=EB=8D=A4=20?= =?UTF-8?q?=ED=82=A4=EC=9B=8C=EB=93=9C=20=EC=84=A0=ED=83=9D=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/repository/QuestionRepository.java | 7 ------- .../service/question/QuestionRetriever.java | 14 -------------- .../service/question/QuestionService.java | 17 ++++++++--------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/telepigeon/server/repository/QuestionRepository.java b/src/main/java/com/telepigeon/server/repository/QuestionRepository.java index 25f47bf..8aa99c6 100644 --- a/src/main/java/com/telepigeon/server/repository/QuestionRepository.java +++ b/src/main/java/com/telepigeon/server/repository/QuestionRepository.java @@ -3,18 +3,11 @@ import com.telepigeon.server.domain.Profile; import com.telepigeon.server.domain.Question; import org.springframework.data.jpa.repository.JpaRepository; -import org.springframework.data.jpa.repository.Query; -import java.util.List; import java.util.Optional; public interface QuestionRepository extends JpaRepository { Optional findFirstByProfileOrderByCreatedAtDesc(Profile profile); boolean existsByProfile(Profile profile); - - List findAllByProfile(Profile profile); - - @Query(value="select q.keyword from question q where q.profile_id = :profileId group by q.keyword order by max(q.created_at) desc limit :count", nativeQuery=true) - List findKeywordsByProfileOrderByCreatedAtDesc(Long profileId, int count); } diff --git a/src/main/java/com/telepigeon/server/service/question/QuestionRetriever.java b/src/main/java/com/telepigeon/server/service/question/QuestionRetriever.java index 95db695..b486808 100644 --- a/src/main/java/com/telepigeon/server/service/question/QuestionRetriever.java +++ b/src/main/java/com/telepigeon/server/service/question/QuestionRetriever.java @@ -8,9 +8,6 @@ import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Component; -import java.util.List; - - @Component @RequiredArgsConstructor public class QuestionRetriever { @@ -32,15 +29,4 @@ public Question findById(final Long questionId){ public boolean existsByProfile(final Profile profile){ return questionRepository.existsByProfile(profile); } - - public List findAllByProfile(final Profile profile) { - return questionRepository.findAllByProfile(profile); - } - - public List findKeywordsByProfile( - final Long profileId, - final int count - ){ - return questionRepository.findKeywordsByProfileOrderByCreatedAtDesc(profileId, count); - } } diff --git a/src/main/java/com/telepigeon/server/service/question/QuestionService.java b/src/main/java/com/telepigeon/server/service/question/QuestionService.java index 0a6785e..5037aec 100644 --- a/src/main/java/com/telepigeon/server/service/question/QuestionService.java +++ b/src/main/java/com/telepigeon/server/service/question/QuestionService.java @@ -22,6 +22,7 @@ import java.util.Arrays; import java.util.List; import java.util.Objects; +import java.util.Random; import static java.time.temporal.ChronoUnit.DAYS; @@ -116,15 +117,13 @@ private String getRandomKeyword(final Profile profile){ return "기분"; } List keywords = Arrays.stream(profile.getKeywords().split(",")).toList(); - List alreadyKeywords = questionRetriever.findKeywordsByProfile( - profile.getId(), - keywords.size() - ); - int i = 0; - for ( ; i < keywords.size(); i++) { - if (!alreadyKeywords.contains(keywords.get(i)) || i == keywords.size() - 1) { - break; - } + if (keywords.size() == 1) + return keywords.get(0); + String alreadyKeyword = questionRetriever.findFirstByProfile(profile).getKeyword(); + Random random = new Random(); + int i = random.nextInt(keywords.size()); + while(alreadyKeyword.equals(keywords.get(i))){ + i = random.nextInt(keywords.size()); } return keywords.get(i); } From 2b59b2b295eb9b3a6123a7abca815ab7937b7f0e Mon Sep 17 00:00:00 2001 From: minwoo0419 Date: Mon, 26 Aug 2024 20:32:14 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[fix]=20#124=20=EB=A1=9C=EA=B9=85=20?= =?UTF-8?q?=EC=A4=84=EB=B0=94=EA=BF=88=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telepigeon/server/service/answer/AnswerService.java | 2 +- .../java/com/telepigeon/server/service/external/FcmService.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/telepigeon/server/service/answer/AnswerService.java b/src/main/java/com/telepigeon/server/service/answer/AnswerService.java index f52cdaf..4482722 100644 --- a/src/main/java/com/telepigeon/server/service/answer/AnswerService.java +++ b/src/main/java/com/telepigeon/server/service/answer/AnswerService.java @@ -111,7 +111,7 @@ public Answer create( roomId ) ); - log.info("답장 생성 완료.\n내용 : {}\n감정 점수 : {}\n이전 평균 감정 점수 : {}\n현재 평균 감정 점수 : {}", answer.getContent(), answer.getEmotion(), preEmotion, profile.getEmotion()); + log.info("\n답장 생성 완료.\n내용 : {}\n감정 점수 : {}\n이전 평균 감정 점수 : {}\n현재 평균 감정 점수 : {}", answer.getContent(), answer.getEmotion(), preEmotion, profile.getEmotion()); return answer; } diff --git a/src/main/java/com/telepigeon/server/service/external/FcmService.java b/src/main/java/com/telepigeon/server/service/external/FcmService.java index 12316b2..686fd48 100644 --- a/src/main/java/com/telepigeon/server/service/external/FcmService.java +++ b/src/main/java/com/telepigeon/server/service/external/FcmService.java @@ -19,7 +19,7 @@ public void send( Message message = createMessage(fcmToken, fcmMessageDto); try{ FirebaseMessaging.getInstance().send(message); - log.info("{} 사용자 -> {} 사용자 푸시 알림 성공.\n알림 유형 : {}\n내용 : {}", fcmMessageDto.senderName(), fcmMessageDto.receiverName(), fcmMessageDto.type(), fcmMessageDto.body()); + log.info("\n{} 사용자 -> {} 사용자 푸시 알림 성공.\n알림 유형 : {}\n내용 : {}", fcmMessageDto.senderName(), fcmMessageDto.receiverName(), fcmMessageDto.type(), fcmMessageDto.body()); } catch (FirebaseMessagingException e){ log.error("Failed to send message. fcm Token : {}", fcmToken); } From 1faf9bfc3110b085f3c1f1b3752d0c9f77e9abb8 Mon Sep 17 00:00:00 2001 From: minwoo0419 Date: Mon, 26 Aug 2024 20:40:12 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[fix]=20#124=20=EC=98=81=EC=83=81=20?= =?UTF-8?q?=EC=9A=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=ED=95=A8=EC=88=98=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/telepigeon/server/controller/TestController.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/telepigeon/server/controller/TestController.java b/src/main/java/com/telepigeon/server/controller/TestController.java index e8a0aba..2a3e70a 100644 --- a/src/main/java/com/telepigeon/server/controller/TestController.java +++ b/src/main/java/com/telepigeon/server/controller/TestController.java @@ -12,11 +12,13 @@ import com.telepigeon.server.service.openAi.OpenAiService; import com.telepigeon.server.utils.JwtUtil; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import java.net.URI; +@Slf4j @RestController @RequestMapping("/api/v1") @RequiredArgsConstructor @@ -67,9 +69,13 @@ public ResponseEntity testOpenAi( @RequestParam(required = false) String ageRange, @RequestParam boolean easyMode ) { - return ResponseEntity.ok(openAiService.createQuestion(relation, keyword, gender, ageRange, easyMode)); + String question = openAiService.createQuestion(relation, keyword, gender, ageRange, easyMode); + log.info("\n질문 생성 완료.\n입력 정보 : 관계 - {} / 키워드 - {} / 성별 - {} / 연령대 - {} / 쉬운 사용 모드 - {}\n내용 : {}", relation, keyword, gender, ageRange, easyMode, question); + return ResponseEntity.ok(question); } + + @GetMapping("/test/emotion") public ResponseEntity testEmotion( @RequestBody ConfidenceCreateDto text