diff --git a/Api/src/main/java/tify/server/api/answer/service/RetrieveDailyAnswerUseCase.java b/Api/src/main/java/tify/server/api/answer/service/RetrieveDailyAnswerUseCase.java index 605aec3e..b655e70a 100644 --- a/Api/src/main/java/tify/server/api/answer/service/RetrieveDailyAnswerUseCase.java +++ b/Api/src/main/java/tify/server/api/answer/service/RetrieveDailyAnswerUseCase.java @@ -19,11 +19,7 @@ import tify.server.domain.domains.question.domain.DailyQuestion; import tify.server.domain.domains.question.dto.condition.AnswerCondition; 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.Neighbor; -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 @@ -31,9 +27,7 @@ @RequiredArgsConstructor public class RetrieveDailyAnswerUseCase { - private final UserAdaptor userAdaptor; private final AnswerAdaptor answerAdaptor; - private final UserBlockAdaptor userBlockAdaptor; private final NeighborAdaptor neighborAdaptor; private final DailyQuestionAdaptor dailyQuestionAdaptor; private final KnockAdaptor knockAdaptor; @@ -56,17 +50,7 @@ public List execute(Long questionId) { @Transactional(readOnly = true) public List executeNeighborAnswerList(Long questionId, Long userId) { - List blockedIdList = - userBlockAdaptor.queryAllByFromUserId(userId).stream() - .map(UserBlock::getToUserId) - .toList(); - List friendIdList = - neighborAdaptor.queryAllByFromUserId(userId).stream() - .map(Neighbor::getToUserId) - .toList(); - NeighborCondition neighborCondition = - new NeighborCondition(userId, blockedIdList, friendIdList); - List neighbors = neighborAdaptor.searchNeighbors(neighborCondition); + List neighbors = neighborAdaptor.searchNeighbors(userId); return neighbors.stream() .map( dto -> { diff --git a/Api/src/main/java/tify/server/api/user/service/AcceptanceNeighborApplicationUseCase.java b/Api/src/main/java/tify/server/api/user/service/AcceptanceNeighborApplicationUseCase.java index fc1c6a0b..8922f5d5 100644 --- a/Api/src/main/java/tify/server/api/user/service/AcceptanceNeighborApplicationUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/AcceptanceNeighborApplicationUseCase.java @@ -39,7 +39,8 @@ public void execute(Long neighborApplicationId) { throw AlreadyExistNeighborRelationshipException.EXCEPTION; } - List neighbors = neighborAdaptor.queryAllByFromUserId(currentUserId); + List fromNeighbors = neighborAdaptor.queryAllByFromUserId(currentUserId); + List toNeighbors = neighborAdaptor.queryAllByFromUserId(toUserId); neighborAdaptor.save( Neighbor.builder() @@ -47,7 +48,16 @@ public void execute(Long neighborApplicationId) { .toUserId(toUserId) .isView(true) .isNew(true) - .order((long) neighbors.size() + 1L) + .order((long) fromNeighbors.size() + 1L) + .build()); + + neighborAdaptor.save( + Neighbor.builder() + .fromUserId(toUserId) + .toUserId(currentUserId) + .isView(true) + .isNew(true) + .order((long) toNeighbors.size() + 1L) .build()); } } diff --git a/Api/src/main/java/tify/server/api/user/service/CreateNeighborUseCase.java b/Api/src/main/java/tify/server/api/user/service/CreateNeighborUseCase.java index 5ff0bedc..0f1c3bcf 100644 --- a/Api/src/main/java/tify/server/api/user/service/CreateNeighborUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/CreateNeighborUseCase.java @@ -1,14 +1,12 @@ package tify.server.api.user.service; -import java.util.List; import lombok.RequiredArgsConstructor; import org.springframework.transaction.annotation.Transactional; import tify.server.api.config.security.SecurityUtils; 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.domain.Neighbor; import tify.server.domain.domains.user.domain.NeighborApplication; import tify.server.domain.domains.user.domain.User; import tify.server.domain.domains.user.exception.AlreadyExistNeighborRelationshipException; @@ -33,16 +31,6 @@ public void execute(Long toUserId) { if (neighborAdaptor.existsNeighbor(currentUserId, toUser.getId())) { throw AlreadyExistNeighborRelationshipException.EXCEPTION; } - List neighbors = neighborAdaptor.queryAllByFromUserId(currentUserId); - - neighborAdaptor.save( - Neighbor.builder() - .fromUserId(currentUserId) - .toUserId(toUser.getId()) - .isView(true) - .isNew(true) - .order((long) neighbors.size() + 1L) - .build()); // 반대편에서 이미 친구가 되어있다면 신청을 보내지 않음 if (!neighborAdaptor diff --git a/Api/src/main/java/tify/server/api/user/service/RejectNeighborApplicationUseCase.java b/Api/src/main/java/tify/server/api/user/service/RejectNeighborApplicationUseCase.java index 7375ac85..e90a71f5 100644 --- a/Api/src/main/java/tify/server/api/user/service/RejectNeighborApplicationUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/RejectNeighborApplicationUseCase.java @@ -30,7 +30,8 @@ public void execute(Long neighborApplicationId) { Neighbor neighbor = neighborAdaptor - .queryByFromUserIdAndToUserId(neighborApplicationId, currentUserId) + .queryByFromUserIdAndToUserId( + neighborApplication.getFromUserId(), currentUserId) .orElseThrow(() -> NeighborNotFoundException.EXCEPTION); neighborAdaptor.delete(neighbor); } diff --git a/Api/src/main/java/tify/server/api/user/service/RemoveNeighborUseCase.java b/Api/src/main/java/tify/server/api/user/service/RemoveNeighborUseCase.java index 0f62098d..12e4de1b 100644 --- a/Api/src/main/java/tify/server/api/user/service/RemoveNeighborUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/RemoveNeighborUseCase.java @@ -6,8 +6,6 @@ import tify.server.api.config.security.SecurityUtils; import tify.server.core.annotation.UseCase; import tify.server.domain.domains.user.adaptor.NeighborAdaptor; -import tify.server.domain.domains.user.domain.Neighbor; -import tify.server.domain.domains.user.exception.NeighborNotFoundException; import tify.server.domain.domains.user.validator.UserValidator; @UseCase @@ -21,17 +19,11 @@ public class RemoveNeighborUseCase { public void execute(Long toUserId) { Long userId = SecurityUtils.getCurrentUserId(); userValidator.isNeighbor(userId, toUserId); - - Neighbor fromNeighbor = - neighborAdaptor - .queryByFromUserIdAndToUserId(userId, toUserId) - .orElseThrow(() -> NeighborNotFoundException.EXCEPTION); - Neighbor toNeighbor = - neighborAdaptor - .queryByFromUserIdAndToUserId(toUserId, userId) - .orElseThrow(() -> NeighborNotFoundException.EXCEPTION); - - neighborAdaptor.delete(fromNeighbor); - neighborAdaptor.delete(toNeighbor); + neighborAdaptor + .queryByFromUserIdAndToUserId(userId, toUserId) + .ifPresent(neighborAdaptor::delete); + neighborAdaptor + .queryByFromUserIdAndToUserId(toUserId, userId) + .ifPresent(neighborAdaptor::delete); } } 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 3f5133cb..3385acf2 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 @@ -8,9 +8,6 @@ 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.Neighbor; -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; @UseCase @@ -24,16 +21,6 @@ public class RetrieveBirthdayNeighborUseCase { @Transactional(readOnly = true) public List execute() { Long currentUserId = userUtils.getUserId(); - List blockedUserList = - userBlockAdaptor.queryAllByFromUserId(currentUserId).stream() - .map(UserBlock::getToUserId) - .toList(); - List friendIdList = - neighborAdaptor.queryAllByToUserId(currentUserId).stream() - .map(Neighbor::getFromUserId) - .toList(); - NeighborCondition neighborCondition = - new NeighborCondition(currentUserId, blockedUserList, friendIdList); - return neighborAdaptor.searchBirthdayNeighbors(neighborCondition); + return neighborAdaptor.searchBirthdayNeighbors(currentUserId); } } 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 21c52e87..6d77f6c6 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 @@ -10,9 +10,6 @@ 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.Neighbor; -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 @@ -28,33 +25,13 @@ public class RetrieveNeighborListUseCase { @Transactional(readOnly = true) public List execute() { Long currentUserId = userUtils.getUserId(); - List blockedUserList = - userBlockAdaptor.queryAllByFromUserId(currentUserId).stream() - .map(UserBlock::getToUserId) - .toList(); - List friendIdList = - neighborAdaptor.queryAllByToUserId(currentUserId).stream() - .map(Neighbor::getFromUserId) - .toList(); - NeighborCondition neighborCondition = - new NeighborCondition(currentUserId, blockedUserList, friendIdList); - return neighborAdaptor.searchNeighbors(neighborCondition); + return neighborAdaptor.searchNeighbors(currentUserId); } @Transactional(readOnly = true) public List executeToIsNew() { Long currentUserId = userUtils.getUserId(); - List blockedUserList = - userBlockAdaptor.queryAllByFromUserId(currentUserId).stream() - .map(UserBlock::getToUserId) - .toList(); - List friendIdList = - neighborAdaptor.queryAllByToUserId(currentUserId).stream() - .map(Neighbor::getFromUserId) - .toList(); - NeighborCondition neighborCondition = - new NeighborCondition(currentUserId, blockedUserList, friendIdList); - return neighborAdaptor.searchNeighbors(neighborCondition).stream() + return neighborAdaptor.searchNeighbors(currentUserId).stream() .filter(RetrieveNeighborDTO::isNew) .toList(); } diff --git a/Api/src/main/java/tify/server/api/user/service/UserBlockUseCase.java b/Api/src/main/java/tify/server/api/user/service/UserBlockUseCase.java index 3f2a1ae1..ce2f95a6 100644 --- a/Api/src/main/java/tify/server/api/user/service/UserBlockUseCase.java +++ b/Api/src/main/java/tify/server/api/user/service/UserBlockUseCase.java @@ -33,7 +33,7 @@ public void execute(Long toUserId) { .optionalQueryByFromUserIdAndToUserId(toUserId, userId) .ifPresent(neighborAdaptor::deleteNeighborApplication); - // 타겟이 되는 유저와 원래 친구였다면 둘의 친구를 끊음 + // 타겟이 되는 유저와 원래 친구였다면 둘의 친구를 끊음 & 두 사람의 친구 목록 업데이트 neighborAdaptor .queryByFromUserIdAndToUserId(userId, toUserId) .ifPresent(neighborAdaptor::delete); diff --git a/Api/src/main/java/tify/server/api/utils/UserUtils.java b/Api/src/main/java/tify/server/api/utils/UserUtils.java index 4b9ac4ac..44e773b2 100644 --- a/Api/src/main/java/tify/server/api/utils/UserUtils.java +++ b/Api/src/main/java/tify/server/api/utils/UserUtils.java @@ -5,6 +5,7 @@ import org.springframework.stereotype.Component; import tify.server.api.config.security.SecurityUtils; import tify.server.domain.domains.user.adaptor.UserAdaptor; +import tify.server.domain.domains.user.adaptor.UserBlockAdaptor; import tify.server.domain.domains.user.domain.User; @Component @@ -12,6 +13,7 @@ public class UserUtils { private final UserAdaptor userAdaptor; + private final UserBlockAdaptor userBlockAdaptor; public Long getUserId() { return SecurityUtils.getCurrentUserId(); 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 886e28be..3ca16445 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 @@ -10,7 +10,6 @@ import tify.server.domain.domains.user.domain.Neighbor; import tify.server.domain.domains.user.domain.NeighborApplication; import tify.server.domain.domains.user.domain.User; -import tify.server.domain.domains.user.dto.condition.NeighborCondition; import tify.server.domain.domains.user.dto.model.GetNeighborApplicationDTO; import tify.server.domain.domains.user.dto.model.RetrieveNeighborDTO; import tify.server.domain.domains.user.exception.NeighborApplicationNotFoundException; @@ -53,13 +52,12 @@ public Optional queryByFromUserIdAndToUserId(Long userId, Long neighbo return neighborRepository.findByFromUserIdAndToUserId(userId, neighborId); } - public List searchNeighbors(NeighborCondition neighborCondition) { - return neighborRepository.searchNeighbors(neighborCondition); + public List searchNeighbors(Long userId) { + return neighborRepository.searchNeighbors(userId); } - public Slice searchNeighbors( - NeighborCondition neighborCondition, Pageable pageable) { - return neighborRepository.searchNeighborsToPage(neighborCondition, pageable); + public Slice searchNeighbors(Long userId, Pageable pageable) { + return neighborRepository.searchNeighborsToPage(userId, pageable); } public boolean existsNeighbor(Long userId, Long neighborId) { @@ -74,8 +72,8 @@ public void delete(Neighbor neighbor) { neighborRepository.delete(neighbor); } - public List searchBirthdayNeighbors(NeighborCondition neighborCondition) { - return neighborRepository.searchBirthdayNeighbors(neighborCondition); + public List searchBirthdayNeighbors(Long userId) { + return neighborRepository.searchBirthdayNeighbors(userId); } public void saveNeighborApplication(NeighborApplication neighborApplication) { @@ -121,4 +119,8 @@ public Optional optionalQueryByFromUserIdAndToUserId( public void deleteNeighborApplication(NeighborApplication neighborApplication) { neighborApplicationRepository.delete(neighborApplication); } + + public List queryAllByFromUserIdOrderByOrder(Long fromUserId) { + return neighborRepository.findAllByFromUserIdOOrderByOrder(fromUserId); + } } diff --git a/Domain/src/main/java/tify/server/domain/domains/user/dto/model/RetrieveNeighborDTO.java b/Domain/src/main/java/tify/server/domain/domains/user/dto/model/RetrieveNeighborDTO.java index 60a2e50f..5ff38772 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/dto/model/RetrieveNeighborDTO.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/dto/model/RetrieveNeighborDTO.java @@ -11,6 +11,8 @@ public class RetrieveNeighborDTO { private Long neighborId; + private Long neighborUserId; + private Long userId; private String neighborThumbnail; 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 9d5ebf39..05aa3f6f 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 @@ -4,15 +4,13 @@ import java.util.List; import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; -import tify.server.domain.domains.user.dto.condition.NeighborCondition; import tify.server.domain.domains.user.dto.model.RetrieveNeighborDTO; public interface NeighborCustomRepository { - List searchNeighbors(NeighborCondition neighborCondition); + List searchNeighbors(Long userId); - List searchBirthdayNeighbors(NeighborCondition neighborCondition); + List searchBirthdayNeighbors(Long userId); - Slice searchNeighborsToPage( - NeighborCondition neighborCondition, Pageable pageable); + Slice searchNeighborsToPage(Long userId, Pageable pageable); } 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 17318b24..1edd1e63 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 @@ -14,7 +14,6 @@ import org.springframework.data.domain.Pageable; 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; @RequiredArgsConstructor @@ -22,11 +21,12 @@ public class NeighborCustomRepositoryImpl implements NeighborCustomRepository { private final JPAQueryFactory queryFactory; @Override - public List searchNeighbors(NeighborCondition neighborCondition) { + public List searchNeighbors(Long userId) { return queryFactory .select( Projections.constructor( RetrieveNeighborDTO.class, + neighbor.id, neighbor.toUserId, neighbor.fromUserId, user.profile.thumbNail, @@ -41,16 +41,13 @@ public List searchNeighbors(NeighborCondition neighborCondi .from(neighbor) .join(user) .on(user.id.eq(neighbor.toUserId)) - .where( - neighbor.fromUserId.eq(neighborCondition.getCurrentUserId()), - neighbor.toUserId.notIn(neighborCondition.getBlockedUserIdList()), - neighbor.toUserId.in(neighborCondition.getFriendIdList())) + .where(neighbor.fromUserId.eq(userId)) .orderBy(neighbor.order.asc()) .fetch(); } @Override - public List searchBirthdayNeighbors(NeighborCondition neighborCondition) { + public List searchBirthdayNeighbors(Long userId) { LocalDateTime today = LocalDateTime.now(ZoneId.of("Asia/Seoul")); String monthAndYear = String.format("%02d%02d", today.getMonth().getValue(), today.getDayOfMonth()); @@ -58,6 +55,7 @@ public List searchBirthdayNeighbors(NeighborCondition neigh .select( Projections.constructor( RetrieveNeighborDTO.class, + neighbor.id, neighbor.toUserId, neighbor.fromUserId, user.profile.thumbNail, @@ -72,23 +70,19 @@ public List searchBirthdayNeighbors(NeighborCondition neigh .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), - neighbor.toUserId.in(neighborCondition.getFriendIdList())) + .where(neighbor.fromUserId.eq(userId), user.profile.birth.contains(monthAndYear)) .orderBy(neighbor.order.asc()) .fetch(); } @Override - public Slice searchNeighborsToPage( - NeighborCondition neighborCondition, Pageable pageable) { + public Slice searchNeighborsToPage(Long userId, Pageable pageable) { List retrieveNeighborDTOS = queryFactory .select( Projections.constructor( RetrieveNeighborDTO.class, + neighbor.id, neighbor.toUserId, neighbor.fromUserId, user.profile.thumbNail, @@ -103,10 +97,7 @@ public Slice searchNeighborsToPage( .from(neighbor) .join(user) .on(user.id.eq(neighbor.toUserId)) - .where( - neighbor.fromUserId.eq(neighborCondition.getCurrentUserId()), - neighbor.toUserId.notIn(neighborCondition.getBlockedUserIdList()), - neighbor.toUserId.in(neighborCondition.getFriendIdList())) + .where(neighbor.fromUserId.eq(userId)) .orderBy(neighbor.order.asc()) .offset(pageable.getOffset()) .limit(pageable.getPageSize()) diff --git a/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborRepository.java b/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborRepository.java index 974b17e5..672d31b9 100644 --- a/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborRepository.java +++ b/Domain/src/main/java/tify/server/domain/domains/user/repository/NeighborRepository.java @@ -19,4 +19,6 @@ public interface NeighborRepository boolean existsByFromUserIdAndToUserId(Long userId, Long neighborId); List findAllByFromUserIdAndIsView(Long fromUserId, boolean isView); + + List findAllByFromUserIdOOrderByOrder(Long fromUserId); }