diff --git a/Api/src/main/java/tify/server/api/user/controller/UserController.java b/Api/src/main/java/tify/server/api/user/controller/UserController.java index a9969118..16b40845 100644 --- a/Api/src/main/java/tify/server/api/user/controller/UserController.java +++ b/Api/src/main/java/tify/server/api/user/controller/UserController.java @@ -124,7 +124,7 @@ public OnBoardingStatusResponse getOnBoardingStatus( @Operation(summary = "친구 목록 조회") @GetMapping("/neighbors") - public SliceResponse getNeighbors( + public List getNeighbors( @ParameterObject @PageableDefault(size = 10) Pageable pageable) { return retrieveNeighborListUseCase.execute(pageable); } @@ -149,7 +149,7 @@ public void postNeighbor(@PathVariable Long toUserId) { @Operation(summary = "생일인 친구 조회") @GetMapping("/neighbors/birthday") - public SliceResponse getBirthdayNeighbor( + public List getBirthdayNeighbor( @ParameterObject @PageableDefault Pageable pageable) { return retrieveBirthdayNeighborUseCase.execute(pageable); } diff --git a/Api/src/main/java/tify/server/api/user/service/RetrieveBirthdayNeighborUseCase.java b/Api/src/main/java/tify/server/api/user/service/RetrieveBirthdayNeighborUseCase.java index 55ac9280..cbecb388 100644 --- a/Api/src/main/java/tify/server/api/user/service/RetrieveBirthdayNeighborUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/RetrieveBirthdayNeighborUseCase.java @@ -1,14 +1,15 @@ package tify.server.api.user.service; +import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.transaction.annotation.Transactional; -import tify.server.api.common.slice.SliceResponse; import tify.server.api.utils.UserUtils; import tify.server.core.annotation.UseCase; import tify.server.domain.domains.user.adaptor.NeighborAdaptor; +import tify.server.domain.domains.user.adaptor.UserBlockAdaptor; +import tify.server.domain.domains.user.domain.UserBlock; import tify.server.domain.domains.user.dto.condition.NeighborCondition; import tify.server.domain.domains.user.dto.model.RetrieveNeighborDTO; @@ -17,14 +18,18 @@ public class RetrieveBirthdayNeighborUseCase { private final NeighborAdaptor neighborAdaptor; + private final UserBlockAdaptor userBlockAdaptor; private final UserUtils userUtils; @Transactional(readOnly = true) - public SliceResponse execute(Pageable pageable) { + public List execute(Pageable pageable) { Long currentUserId = userUtils.getUserId(); - NeighborCondition neighborCondition = new NeighborCondition(currentUserId, pageable); - Slice neighborDTOS = - neighborAdaptor.searchBirthdayNeighbors(neighborCondition); - return SliceResponse.of(neighborDTOS); + List blockedUserList = + userBlockAdaptor.queryAllByFromUserId(currentUserId).stream() + .map(UserBlock::getToUserId) + .toList(); + NeighborCondition neighborCondition = + new NeighborCondition(currentUserId, blockedUserList, pageable); + return neighborAdaptor.searchBirthdayNeighbors(neighborCondition); } } diff --git a/Api/src/main/java/tify/server/api/user/service/RetrieveNeighborListUseCase.java b/Api/src/main/java/tify/server/api/user/service/RetrieveNeighborListUseCase.java index 6918e9c1..774d1908 100644 --- a/Api/src/main/java/tify/server/api/user/service/RetrieveNeighborListUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/RetrieveNeighborListUseCase.java @@ -1,32 +1,39 @@ package tify.server.api.user.service; +import java.util.List; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.data.domain.Pageable; -import org.springframework.data.domain.Slice; import org.springframework.transaction.annotation.Transactional; -import tify.server.api.common.slice.SliceResponse; import tify.server.api.utils.UserUtils; import tify.server.core.annotation.UseCase; import tify.server.domain.domains.user.adaptor.NeighborAdaptor; import tify.server.domain.domains.user.adaptor.UserAdaptor; +import tify.server.domain.domains.user.adaptor.UserBlockAdaptor; +import tify.server.domain.domains.user.domain.UserBlock; import tify.server.domain.domains.user.dto.condition.NeighborCondition; import tify.server.domain.domains.user.dto.model.RetrieveNeighborDTO; +@Slf4j @UseCase @RequiredArgsConstructor public class RetrieveNeighborListUseCase { private final NeighborAdaptor neighborAdaptor; private final UserAdaptor userAdaptor; + private final UserBlockAdaptor userBlockAdaptor; private final UserUtils userUtils; @Transactional(readOnly = true) - public SliceResponse execute(Pageable pageable) { + public List execute(Pageable pageable) { Long currentUserId = userUtils.getUserId(); - NeighborCondition neighborCondition = new NeighborCondition(currentUserId, pageable); - Slice neighborDTOS = - neighborAdaptor.searchNeighbors(neighborCondition); - return SliceResponse.of(neighborDTOS); + List blockedUserList = + userBlockAdaptor.queryAllByFromUserId(currentUserId).stream() + .map(UserBlock::getToUserId) + .toList(); + NeighborCondition neighborCondition = + new NeighborCondition(currentUserId, blockedUserList, pageable); + return neighborAdaptor.searchNeighbors(neighborCondition); } } diff --git a/Domain/src/main/java/tify/server/domain/domains/user/adaptor/NeighborAdaptor.java b/Domain/src/main/java/tify/server/domain/domains/user/adaptor/NeighborAdaptor.java index 8581b3d6..f2022c5b 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/adaptor/NeighborAdaptor.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/adaptor/NeighborAdaptor.java @@ -49,7 +49,7 @@ public Optional queryByFromUserIdAndToUserId(Long userId, Long neighbo return neighborRepository.findByFromUserIdAndToUserId(userId, neighborId); } - public Slice searchNeighbors(NeighborCondition neighborCondition) { + public List searchNeighbors(NeighborCondition neighborCondition) { return neighborRepository.searchToPage(neighborCondition); } @@ -65,7 +65,7 @@ public void delete(Neighbor neighbor) { neighborRepository.delete(neighbor); } - public Slice searchBirthdayNeighbors(NeighborCondition neighborCondition) { + public List searchBirthdayNeighbors(NeighborCondition neighborCondition) { return neighborRepository.searchBirthToPage(neighborCondition); } diff --git a/Domain/src/main/java/tify/server/domain/domains/user/adaptor/UserBlockAdaptor.java b/Domain/src/main/java/tify/server/domain/domains/user/adaptor/UserBlockAdaptor.java index 2de44a1d..e177cd42 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/adaptor/UserBlockAdaptor.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/adaptor/UserBlockAdaptor.java @@ -1,6 +1,7 @@ package tify.server.domain.domains.user.adaptor; +import java.util.List; import java.util.Optional; import lombok.RequiredArgsConstructor; import tify.server.core.annotation.Adaptor; @@ -28,6 +29,10 @@ public Optional queryByFromUserIdAndToUserId(Long fromUserId, Long to return userBlockRepository.findByFromUserIdAndToUserId(fromUserId, toUserId); } + public List queryAllByFromUserId(Long fromUserId) { + return userBlockRepository.findAllByFromUserId(fromUserId); + } + public void save(Long fromUserId, Long toUserId) { userBlockRepository.save( UserBlock.builder().fromUserId(fromUserId).toUserId(toUserId).build()); diff --git a/Domain/src/main/java/tify/server/domain/domains/user/dto/condition/NeighborCondition.java b/Domain/src/main/java/tify/server/domain/domains/user/dto/condition/NeighborCondition.java index df39ef53..1150906b 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/dto/condition/NeighborCondition.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/dto/condition/NeighborCondition.java @@ -1,6 +1,7 @@ package tify.server.domain.domains.user.dto.condition; +import java.util.List; import lombok.AllArgsConstructor; import lombok.Getter; import org.springframework.data.domain.Pageable; @@ -9,6 +10,7 @@ @AllArgsConstructor public class NeighborCondition { - Long currentUserId; + private Long currentUserId; + private List blockedUserIdList; private Pageable pageable; } diff --git a/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepository.java b/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepository.java index 528ad972..db7bb035 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepository.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepository.java @@ -1,13 +1,13 @@ package tify.server.domain.domains.user.repository; -import org.springframework.data.domain.Slice; +import java.util.List; import tify.server.domain.domains.user.dto.condition.NeighborCondition; import tify.server.domain.domains.user.dto.model.RetrieveNeighborDTO; public interface NeighborCustomRepository { - Slice searchToPage(NeighborCondition neighborCondition); + List searchToPage(NeighborCondition neighborCondition); - Slice searchBirthToPage(NeighborCondition neighborCondition); + List searchBirthToPage(NeighborCondition neighborCondition); } diff --git a/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepositoryImpl.java b/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepositoryImpl.java index 9d54993e..d4370b3c 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepositoryImpl.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborCustomRepositoryImpl.java @@ -2,7 +2,6 @@ import static tify.server.domain.domains.user.domain.QNeighbor.neighbor; import static tify.server.domain.domains.user.domain.QUser.user; -import static tify.server.domain.domains.user.domain.QUserBlock.userBlock; import com.querydsl.core.types.Projections; import com.querydsl.jpa.impl.JPAQueryFactory; @@ -10,8 +9,6 @@ import java.time.ZoneId; import java.util.List; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Slice; -import tify.server.domain.common.util.SliceUtil; import tify.server.domain.domains.user.dto.condition.NeighborCondition; import tify.server.domain.domains.user.dto.model.RetrieveNeighborDTO; @@ -20,72 +17,62 @@ public class NeighborCustomRepositoryImpl implements NeighborCustomRepository { private final JPAQueryFactory queryFactory; @Override - public Slice searchToPage(NeighborCondition neighborCondition) { - List neighbors = - queryFactory - .select( - Projections.constructor( - RetrieveNeighborDTO.class, - neighbor.toUserId, - neighbor.fromUserId, - user.profile.thumbNail, - user.profile.userName, - user.profile.birth, - user.onBoardingStatus.name, - neighbor.order, - neighbor.isView, - user.updatedAt, - neighbor.viewedAt)) - .from(neighbor) - .join(user) - .on(user.id.eq(neighbor.toUserId)) - .join(userBlock) - .on(userBlock.fromUserId.eq(neighbor.fromUserId)) - .where( - neighbor.fromUserId.eq(neighborCondition.getCurrentUserId()), - neighbor.toUserId.ne(userBlock.toUserId)) - .orderBy(neighbor.order.asc()) - .offset(neighborCondition.getPageable().getOffset()) - .limit(neighborCondition.getPageable().getPageSize() + 1) - .fetch(); - - return SliceUtil.valueOf(neighbors, neighborCondition.getPageable()); + public List searchToPage(NeighborCondition neighborCondition) { + return queryFactory + .select( + Projections.constructor( + RetrieveNeighborDTO.class, + neighbor.toUserId, + neighbor.fromUserId, + user.profile.thumbNail, + user.profile.userName, + user.profile.birth, + user.onBoardingStatus.name, + neighbor.order, + neighbor.isView, + user.updatedAt, + neighbor.viewedAt)) + .from(neighbor) + .join(user) + .on(user.id.eq(neighbor.toUserId)) + .where( + neighbor.fromUserId.eq(neighborCondition.getCurrentUserId()), + neighbor.toUserId.notIn(neighborCondition.getBlockedUserIdList())) + .orderBy(neighbor.order.asc()) + .offset(neighborCondition.getPageable().getOffset()) + .limit(neighborCondition.getPageable().getPageSize() + 1) + .fetch(); } @Override - public Slice searchBirthToPage(NeighborCondition neighborCondition) { + public List searchBirthToPage(NeighborCondition neighborCondition) { LocalDateTime today = LocalDateTime.now(ZoneId.of("Asia/Seoul")); String monthAndYear = String.format("%02d%02d", today.getMonth().getValue(), today.getDayOfMonth()); - List neighbors = - queryFactory - .select( - Projections.constructor( - RetrieveNeighborDTO.class, - neighbor.toUserId, - neighbor.fromUserId, - user.profile.thumbNail, - user.profile.userName, - user.profile.birth, - user.onBoardingStatus.name, - neighbor.order, - neighbor.isView, - user.updatedAt, - neighbor.viewedAt)) - .from(neighbor) - .join(user) - .on(user.id.eq(neighbor.toUserId)) - .join(userBlock) - .on(userBlock.fromUserId.eq(neighbor.fromUserId)) - .where( - neighbor.fromUserId.eq(neighborCondition.getCurrentUserId()), - neighbor.toUserId.ne(userBlock.toUserId), - user.profile.birth.contains(monthAndYear)) - .orderBy(neighbor.order.asc()) - .offset(neighborCondition.getPageable().getOffset()) - .limit(neighborCondition.getPageable().getPageSize() + 1) - .fetch(); - - return SliceUtil.valueOf(neighbors, neighborCondition.getPageable()); + return queryFactory + .select( + Projections.constructor( + RetrieveNeighborDTO.class, + neighbor.toUserId, + neighbor.fromUserId, + user.profile.thumbNail, + user.profile.userName, + user.profile.birth, + user.onBoardingStatus.name, + neighbor.order, + neighbor.isView, + user.updatedAt, + neighbor.viewedAt)) + .from(neighbor) + .join(user) + .on(user.id.eq(neighbor.toUserId)) + .where( + neighbor.fromUserId.eq(neighborCondition.getCurrentUserId()), + neighbor.toUserId.notIn(neighborCondition.getBlockedUserIdList()), + user.profile.birth.contains(monthAndYear)) + .orderBy(neighbor.order.asc()) + .offset(neighborCondition.getPageable().getOffset()) + .limit(neighborCondition.getPageable().getPageSize() + 1) + .fetch(); } } diff --git a/Domain/src/main/java/tify/server/domain/domains/user/repository/UserBlockRepository.java b/Domain/src/main/java/tify/server/domain/domains/user/repository/UserBlockRepository.java index 5ee9dc28..2a2a0793 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/repository/UserBlockRepository.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/repository/UserBlockRepository.java @@ -1,6 +1,7 @@ package tify.server.domain.domains.user.repository; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import tify.server.domain.domains.user.domain.UserBlock; @@ -10,4 +11,6 @@ public interface UserBlockRepository extends JpaRepository { public Optional findByFromUserIdAndToUserId(Long fromUserId, Long toUserId); public boolean existsByFromUserIdAndToUserId(Long fromUserId, Long toUserId); + + public List findAllByFromUserId(Long fromUserId); }