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 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/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); } 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); }