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/**",