diff --git a/src/main/java/org/sopt/app/application/poke/PokeMessageService.java b/src/main/java/org/sopt/app/application/poke/PokeMessageService.java index e7aacbfd..1ff7c5f1 100644 --- a/src/main/java/org/sopt/app/application/poke/PokeMessageService.java +++ b/src/main/java/org/sopt/app/application/poke/PokeMessageService.java @@ -1,14 +1,13 @@ package org.sopt.app.application.poke; import lombok.RequiredArgsConstructor; +import lombok.val; import org.sopt.app.domain.entity.PokeMessage; import org.sopt.app.domain.enums.PokeMessageType; import org.sopt.app.interfaces.postgres.PokeMessageRepository; -import org.sopt.app.application.poke.PokeInfo.PokeMessageDetail; import org.springframework.stereotype.Service; import java.util.*; -import java.util.stream.Collectors; @Service @RequiredArgsConstructor @@ -17,25 +16,13 @@ public class PokeMessageService { private static final int MESSAGES_QUANTITY_AT_ONCE = 5; private final PokeMessageRepository messageRepository; - public List pickRandomMessageIdsTypeOf(String type) { + public List pickRandomMessageByTypeOf(String type) { PokeMessageType messageType = PokeMessageType.ofParam(type); - List allMessageIds = messageRepository.findAllByType(messageType).stream() - .map(PokeMessage::getId) - .collect(Collectors.toList()); - Collections.shuffle(allMessageIds, new Random()); - return allMessageIds.stream() + val messages = messageRepository.findAllByType(messageType); + Collections.shuffle(messages, new Random()); + return messages.stream() .limit(MESSAGES_QUANTITY_AT_ONCE) .toList(); } - - public List getMessagesDetail(List messageIds) { - return messageRepository.findAllByIdIn(messageIds).stream() - .map(pokeMessage -> PokeMessageDetail.builder() - .id(pokeMessage.getId()) - .content(pokeMessage.getContent()) - .build()) - .collect(Collectors.toList()); - } - } diff --git a/src/main/java/org/sopt/app/facade/PokeFacade.java b/src/main/java/org/sopt/app/facade/PokeFacade.java index 11af8cbf..a17a8dc8 100644 --- a/src/main/java/org/sopt/app/facade/PokeFacade.java +++ b/src/main/java/org/sopt/app/facade/PokeFacade.java @@ -35,9 +35,8 @@ public class PokeFacade { @Transactional(readOnly = true) public List getPokingMessages(String type) { - List targetMessageIds = pokeMessageService.pickRandomMessageIdsTypeOf(type); - List messagesDetails = pokeMessageService.getMessagesDetail(targetMessageIds); - return messagesDetails.stream() + val messages = pokeMessageService.pickRandomMessageByTypeOf(type); + return messages.stream() .map(messagesDetail -> PokeResponse.PokeMessage.of( messagesDetail.getId(), messagesDetail.getContent() ) diff --git a/src/main/java/org/sopt/app/interfaces/postgres/PokeMessageRepository.java b/src/main/java/org/sopt/app/interfaces/postgres/PokeMessageRepository.java index 27d0aabf..4bb6f58a 100644 --- a/src/main/java/org/sopt/app/interfaces/postgres/PokeMessageRepository.java +++ b/src/main/java/org/sopt/app/interfaces/postgres/PokeMessageRepository.java @@ -10,9 +10,5 @@ public interface PokeMessageRepository extends JpaRepository { - @Query("SELECT pm FROM PokeMessage pm WHERE pm.type = :type") - List findAllByType(@Param("type") PokeMessageType type); - - @Query("SELECT pm FROM PokeMessage pm WHERE pm.id in :messageIds") - List findAllByIdIn(@Param("messageIds") List messageIds); + List findAllByType(PokeMessageType type); } \ No newline at end of file