From 14b7cfd39141acbda0c77db8f7693f825af8a2ef Mon Sep 17 00:00:00 2001 From: gypark Date: Wed, 18 Dec 2024 00:52:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20mailbox=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/repository/CoffeeChatsRepository.java | 3 +++ .../coffeeChats/CoffeeChatsGetAllService.java | 17 ++++++++++++++--- .../persistence/CoffeeChatsService.java | 5 +++++ 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/flow/main/repository/CoffeeChatsRepository.java b/src/main/java/com/flow/main/repository/CoffeeChatsRepository.java index 901e253..c0fd7cc 100644 --- a/src/main/java/com/flow/main/repository/CoffeeChatsRepository.java +++ b/src/main/java/com/flow/main/repository/CoffeeChatsRepository.java @@ -14,4 +14,7 @@ public interface CoffeeChatsRepository extends JpaRepository findAllCoffeeChatsByInitiatorUserIdWithPageable(@Param("initiatorUserId") Long initiatorUserId, Pageable pageable); + @Query("SELECT c FROM CoffeeChatsEntity c WHERE c.recipientUser.userId = :recipientUserId") + List findAllCoffeeChatsByRecipientUserIdWithPageable(@Param("recipientUserId") Long recipientUserId, Pageable pageable); + } diff --git a/src/main/java/com/flow/main/service/coffeeChats/CoffeeChatsGetAllService.java b/src/main/java/com/flow/main/service/coffeeChats/CoffeeChatsGetAllService.java index ab01a1d..081e1ed 100644 --- a/src/main/java/com/flow/main/service/coffeeChats/CoffeeChatsGetAllService.java +++ b/src/main/java/com/flow/main/service/coffeeChats/CoffeeChatsGetAllService.java @@ -2,10 +2,11 @@ import org.springframework.data.domain.Pageable; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.springframework.stereotype.Service; -import com.flow.main.dto.controller.coffeeChats.request.CoffeeChatsGetAllRequestDto; import com.flow.main.dto.controller.coffeeChats.response.CoffeeChatsGetAllResponseDto; import com.flow.main.dto.jpa.coffeeChats.CoffeeChatsDto; import com.flow.main.dto.jpa.users.UsersDto; @@ -23,8 +24,18 @@ public class CoffeeChatsGetAllService { public CoffeeChatsGetAllResponseDto getAllWithPageable(String email, Pageable pageable) { UsersDto usersDto = usersService.findByEmail(email); - List coffeeChatsDtoList = coffeeChatsService.getAllByInitiatorUserIdWithPageable(usersDto.getUserId(), pageable); - return CoffeeChatsGetAllResponseDto.builder().coffeeChat(coffeeChatsDtoList).pageable(pageable).build(); + List coffeeChatsDtoListInitiator = coffeeChatsService.getAllByInitiatorUserIdWithPageable(usersDto.getUserId(), pageable); + List coffeeChatsDtoListRecipient = coffeeChatsService.getAllByRecipientUserIdWithPageable(usersDto.getUserId(), pageable); + + List combinedList = Stream.concat( + coffeeChatsDtoListInitiator.stream(), + coffeeChatsDtoListRecipient.stream() + ).collect(Collectors.toList()); + + return CoffeeChatsGetAllResponseDto.builder() + .coffeeChat(combinedList) + .pageable(pageable) + .build(); } } diff --git a/src/main/java/com/flow/main/service/coffeeChats/persistence/CoffeeChatsService.java b/src/main/java/com/flow/main/service/coffeeChats/persistence/CoffeeChatsService.java index 17c1abd..264c301 100644 --- a/src/main/java/com/flow/main/service/coffeeChats/persistence/CoffeeChatsService.java +++ b/src/main/java/com/flow/main/service/coffeeChats/persistence/CoffeeChatsService.java @@ -25,6 +25,11 @@ public List getAllByInitiatorUserIdWithPageable(Long initiatorUs return coffeeChatsMapper.toListDto(coffeeChatsRepository.findAllCoffeeChatsByInitiatorUserIdWithPageable(initiatorUserId, pageable)); } + @Transactional(readOnly = true) + public List getAllByRecipientUserIdWithPageable(Long recipientUserId, Pageable pageable) { + return coffeeChatsMapper.toListDto(coffeeChatsRepository.findAllCoffeeChatsByRecipientUserIdWithPageable(recipientUserId, pageable)); + } + @Transactional public CoffeeChatsDto save(CoffeeChatsDto coffeeChatsDto) { CoffeeChatsEntity coffeeChatsEntity = coffeeChatsMapper.toEntity(coffeeChatsDto);