From 0c833c8128bd24c4b650dd298baa1213636d91ed Mon Sep 17 00:00:00 2001 From: Jeongho Date: Mon, 20 May 2024 20:28:24 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=ED=99=9C=EB=8F=99=20=EB=8B=A4=EC=A4=91?= =?UTF-8?q?=20=EC=84=A0=ED=83=9D=20=EA=B0=80=EB=8A=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dto/request/ReadActivitiesReq.java | 2 +- .../custom/ActivityRepositoryCustom.java | 6 ++-- .../custom/ActivityRepositoryImpl.java | 36 +++++++++---------- .../activity/service/ActivityService.java | 24 +++++++------ 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/main/java/com/meetup/teame/backend/domain/activity/dto/request/ReadActivitiesReq.java b/src/main/java/com/meetup/teame/backend/domain/activity/dto/request/ReadActivitiesReq.java index 2cb6654..ec0482c 100644 --- a/src/main/java/com/meetup/teame/backend/domain/activity/dto/request/ReadActivitiesReq.java +++ b/src/main/java/com/meetup/teame/backend/domain/activity/dto/request/ReadActivitiesReq.java @@ -22,7 +22,7 @@ public class ReadActivitiesReq { @Schema(example = "0") private long page; - private String agencyType; + private List agencyTypes = new ArrayList<>(); private List personalities = new ArrayList<>(); } 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 28b0555..ec70266 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,9 +10,9 @@ public interface ActivityRepositoryCustom { List findActivitiesForUser(User user); - List findByAgencyAndPersonalities(long offset, long limit, AgencyType agencyType, List personalities); + List findByAgencyAndPersonalities(long offset, long limit, List agencyType, List personalities); - List findLikedActivities(Long userId, long offset, long limit, AgencyType agencyType, List personalities); + List findLikedActivities(Long userId, long offset, long limit, List agencyTypes, List personalities); - Long countActivities(AgencyType agencyType, List personalities); + Long countActivities(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 2c64e18..579a706 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,17 +30,15 @@ public List findActivitiesForUser(User user) { } @Override - public List findByAgencyAndPersonalities(long offset, long limit, AgencyType agencyType, List personalities) { + public List findByAgencyAndPersonalities(long offset, long limit, List agencyTypes, List personalities) { BooleanBuilder builder = new BooleanBuilder(); // agencyType나 personalities가 입력된 경우 해당 값으로 필터링 - if (agencyType != null || (personalities != null && !personalities.isEmpty())) { - if (agencyType != null) { - builder.and(activity.agencyType.eq(agencyType)); - } - if (personalities != null && !personalities.isEmpty()) { - builder.and(activity.personalities.any().in(personalities)); - } + if (agencyTypes != null && !agencyTypes.isEmpty()) { + builder.and(activity.agencyType.in(agencyTypes)); + } + if (personalities != null && !personalities.isEmpty()) { + builder.and(activity.personalities.any().in(personalities)); } return jpaQueryFactory @@ -53,7 +51,7 @@ public List findByAgencyAndPersonalities(long offset, long limit, Agen } @Override - public List findLikedActivities(Long userId, long offset, long limit, AgencyType agencyType, List personalities) { + public List findLikedActivities(Long userId, long offset, long limit, List agencyTypes, List personalities) { BooleanBuilder builder = new BooleanBuilder(); // 사용자의 좋아하는 활동 ID 목록을 조회 @@ -72,8 +70,8 @@ public List findLikedActivities(Long userId, long offset, long limit, } // agencyType나 personalities가 입력된 경우 해당 값으로 필터링 - if (agencyType != null) { - builder.and(activity.agencyType.eq(agencyType)); + if (agencyTypes != null && !agencyTypes.isEmpty()) { + builder.and(activity.agencyType.in(agencyTypes)); } if (personalities != null && !personalities.isEmpty()) { builder.and(activity.personalities.any().in(personalities)); @@ -90,17 +88,15 @@ public List findLikedActivities(Long userId, long offset, long limit, @Override - public Long countActivities(AgencyType agencyType, List personalities) { + public Long countActivities(List agencyTypes, List personalities) { BooleanBuilder builder = new BooleanBuilder(); - // agencyType나 personalities가 입력된 경우 해당 값으로 필터링 - if (agencyType != null || (personalities != null && !personalities.isEmpty())) { - if (agencyType != null) { - builder.and(activity.agencyType.eq(agencyType)); - } - if (personalities != null && !personalities.isEmpty()) { - builder.and(activity.personalities.any().in(personalities)); - } + // agencyTypes나 personalities가 입력된 경우 해당 값으로 필터링 + if (agencyTypes != null && !agencyTypes.isEmpty()) { + builder.and(activity.agencyType.in(agencyTypes)); + } + if (personalities != null && !personalities.isEmpty()) { + builder.and(activity.personalities.any().in(personalities)); } return jpaQueryFactory 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 84a555e..3e747e1 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 @@ -58,22 +58,23 @@ public ReadActivitiesRes findActivities(ReadActivitiesReq activitiesReq) { long page = activitiesReq.getPage(); long offset = page * ACTIVITY_PAGE_SIZE; long limit = ACTIVITY_PAGE_SIZE; - AgencyType agencyType = null; + /*AgencyType agencyType = null; if (activitiesReq.getAgencyType() != null) { agencyType = AgencyType.of(activitiesReq.getAgencyType()); - } + }*/ + List agencyTypes = activitiesReq.getAgencyTypes().stream() + .map(AgencyType::of) + .collect(Collectors.toList()); List personalities = activitiesReq.getPersonalities().stream() .map(Personality::of) .collect(Collectors.toList()); - //long totalCount = activityRepository.countActivities(agencyType, personalities); - //long pageCount = (totalCount + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE; // 전체 페이지 수 계산 - long pageCount = activityRepository.countActivities(agencyType, personalities) / ACTIVITY_PAGE_SIZE + 1; // 전체 페이지 수 계산 + long pageCount = activityRepository.countActivities(agencyTypes, personalities) / ACTIVITY_PAGE_SIZE + 1; // 전체 페이지 수 계산 List likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId); Set likedActivityIdsSet = new HashSet<>(likedActivityIds); - List activities = activityRepository.findByAgencyAndPersonalities(offset, limit, agencyType, personalities); + List activities = activityRepository.findByAgencyAndPersonalities(offset, limit, agencyTypes, personalities); List activitySummaries = activities.stream() .map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId()))) .toList(); @@ -89,20 +90,23 @@ public ReadActivitiesRes findlikedActivities(ReadActivitiesReq activitiesReq) { Long page = activitiesReq.getPage(); long offset = page * ACTIVITY_PAGE_SIZE; long limit = ACTIVITY_PAGE_SIZE; - AgencyType agencyType = null; + /*AgencyType agencyType = null; if (activitiesReq.getAgencyType() != null) { agencyType = AgencyType.of(activitiesReq.getAgencyType()); - } + }*/ + List agencyTypes = activitiesReq.getAgencyTypes().stream() + .map(AgencyType::of) + .collect(Collectors.toList()); List personalities = activitiesReq.getPersonalities().stream() .map(Personality::of) .collect(Collectors.toList()); //long totalCount = activityRepository.countActivities(agencyType, personalities); - long pageCount = activityRepository.countActivities(agencyType, personalities) / ACTIVITY_PAGE_SIZE + 1; // 전체 페이지 수 계산 + long pageCount = activityRepository.countActivities(agencyTypes, personalities) / ACTIVITY_PAGE_SIZE + 1; // 전체 페이지 수 계산 List likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId); Set likedActivityIdsSet = new HashSet<>(likedActivityIds); - List activities = activityRepository.findLikedActivities(userId, offset, limit, agencyType, personalities); + List activities = activityRepository.findLikedActivities(userId, offset, limit, agencyTypes, personalities); List activitySummaries = activities.stream() .map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId()))) .toList();