From 77d9eff5ed0c72fddcb808243aa288e9404c824a Mon Sep 17 00:00:00 2001 From: Jeongho Date: Thu, 23 May 2024 00:42:37 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=ED=99=9C=EB=8F=99=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=20=EC=98=A8=EB=B3=B4=EB=94=A9=20=EB=B0=98=EC=98=81=20=EB=B0=8F?= =?UTF-8?q?=20=EC=9D=B5=EB=AA=85=20=EC=9C=A0=EC=A0=80=20=EC=82=AC=EC=9A=A9?= =?UTF-8?q?=20=EB=B0=98=EC=98=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../custom/ActivityRepositoryCustom.java | 2 +- .../custom/ActivityRepositoryImpl.java | 7 ++++++- .../activity/service/ActivityService.java | 21 ++++++++++++------- .../domain/auth/config/SecurityConfig.java | 1 + 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryCustom.java b/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryCustom.java index ec70266..81b561b 100644 --- a/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryCustom.java +++ b/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryCustom.java @@ -10,7 +10,7 @@ public interface ActivityRepositoryCustom { List findActivitiesForUser(User user); - List findByAgencyAndPersonalities(long offset, long limit, List agencyType, List personalities); + List findByAgencyAndPersonalities(long offset, long limit, User user, List agencyTypes, List personalities); List findLikedActivities(Long userId, long offset, long limit, List agencyTypes, List personalities); diff --git a/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryImpl.java b/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryImpl.java index 579a706..7c8a38f 100644 --- a/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryImpl.java +++ b/src/main/java/com/meetup/teame/backend/domain/activity/repository/custom/ActivityRepositoryImpl.java @@ -30,9 +30,14 @@ public List findActivitiesForUser(User user) { } @Override - public List findByAgencyAndPersonalities(long offset, long limit, List agencyTypes, List personalities) { + public List findByAgencyAndPersonalities(long offset, long limit, User user, List agencyTypes, List personalities) { BooleanBuilder builder = new BooleanBuilder(); + //온보딩 정보에 따라 필터링 + if (user != null && !user.getPersonalities().isEmpty()) { + builder.and(activity.personalities.any().in(user.getPersonalities())); + } + // agencyType나 personalities가 입력된 경우 해당 값으로 필터링 if (agencyTypes != null && !agencyTypes.isEmpty()) { builder.and(activity.agencyType.in(agencyTypes)); diff --git a/src/main/java/com/meetup/teame/backend/domain/activity/service/ActivityService.java b/src/main/java/com/meetup/teame/backend/domain/activity/service/ActivityService.java index c932b7b..4a4376c 100644 --- a/src/main/java/com/meetup/teame/backend/domain/activity/service/ActivityService.java +++ b/src/main/java/com/meetup/teame/backend/domain/activity/service/ActivityService.java @@ -12,6 +12,8 @@ import com.meetup.teame.backend.domain.auth.jwt.SecurityContextProvider; import com.meetup.teame.backend.domain.like.repository.ActivityLikeRepository; import com.meetup.teame.backend.domain.personality.Personality; +import com.meetup.teame.backend.domain.user.entity.User; +import com.meetup.teame.backend.domain.user.repository.UserRepository; import com.meetup.teame.backend.global.exception.CustomException; import com.meetup.teame.backend.global.exception.ExceptionContent; import lombok.RequiredArgsConstructor; @@ -36,6 +38,7 @@ public class ActivityService { private final AmazonS3 amazonS3; private final ActivityRepository activityRepository; private final ActivityLikeRepository activityLikeRepository; + private final UserRepository userRepository; private static final int ACTIVITY_PAGE_SIZE = 12; @@ -57,6 +60,9 @@ public ReadActivitiesRes findActivities(ReadActivitiesReq activitiesReq) { if (!SecurityContextProvider.isAnonymousUser()) { userId = SecurityContextProvider.getAuthenticatedUserId(); } + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER)); + long page = activitiesReq.getPage(); long offset = page * ACTIVITY_PAGE_SIZE; long limit = ACTIVITY_PAGE_SIZE; @@ -68,12 +74,14 @@ public ReadActivitiesRes findActivities(ReadActivitiesReq activitiesReq) { .map(Personality::of) .collect(Collectors.toList()); - long pageCount = (activityRepository.countActivities(agencyTypes, personalities) + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE; // 전체 페이지 수 계산 - List likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId); Set likedActivityIdsSet = new HashSet<>(likedActivityIds); - List activities = activityRepository.findByAgencyAndPersonalities(offset, limit, agencyTypes, personalities); + List activities = activityRepository.findByAgencyAndPersonalities(offset, limit, user, agencyTypes, personalities); + + long pageCount = (activities.size() + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE; // 전체 페이지 수 계산 + + List activitySummaries = activities.stream() .map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId()))) .toList(); @@ -97,14 +105,13 @@ public ReadActivitiesRes findlikedActivities(ReadActivitiesReq activitiesReq) { .map(Personality::of) .collect(Collectors.toList()); - //long pageCount = activityRepository.countActivities(agencyTypes, personalities) / ACTIVITY_PAGE_SIZE + 1; // 전체 페이지 수 계산 - List likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId); Set likedActivityIdsSet = new HashSet<>(likedActivityIds); - long pageCount = (likedActivityIds.size() + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE; - List activities = activityRepository.findLikedActivities(userId, offset, limit, agencyTypes, personalities); + + long pageCount = (activities.size() + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE; + List activitySummaries = activities.stream() .map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId()))) .toList(); diff --git a/src/main/java/com/meetup/teame/backend/domain/auth/config/SecurityConfig.java b/src/main/java/com/meetup/teame/backend/domain/auth/config/SecurityConfig.java index 4ca6c89..dd4c559 100644 --- a/src/main/java/com/meetup/teame/backend/domain/auth/config/SecurityConfig.java +++ b/src/main/java/com/meetup/teame/backend/domain/auth/config/SecurityConfig.java @@ -28,6 +28,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { "/send-email", "/register", "/users/main", + "/activities", "/swagger-ui/**", "/swagger-resources/**", "/v3/api-docs/**",