Skip to content

Commit

Permalink
Fix: 활동 다중 선택 가능
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongho427 committed May 20, 2024
1 parent c355bf3 commit 0c833c8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class ReadActivitiesReq {
@Schema(example = "0")
private long page;

private String agencyType;
private List<String> agencyTypes = new ArrayList<>();

private List<String> personalities = new ArrayList<>();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public interface ActivityRepositoryCustom {
List<Activity> findActivitiesForUser(User user);

List<Activity> findByAgencyAndPersonalities(long offset, long limit, AgencyType agencyType, List<Personality> personalities);
List<Activity> findByAgencyAndPersonalities(long offset, long limit, List<AgencyType> agencyType, List<Personality> personalities);

List<Activity> findLikedActivities(Long userId, long offset, long limit, AgencyType agencyType, List<Personality> personalities);
List<Activity> findLikedActivities(Long userId, long offset, long limit, List<AgencyType> agencyTypes, List<Personality> personalities);

Long countActivities(AgencyType agencyType, List<Personality> personalities);
Long countActivities(List<AgencyType> agencyTypes, List<Personality> personalities);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,15 @@ public List<Activity> findActivitiesForUser(User user) {
}

@Override
public List<Activity> findByAgencyAndPersonalities(long offset, long limit, AgencyType agencyType, List<Personality> personalities) {
public List<Activity> findByAgencyAndPersonalities(long offset, long limit, List<AgencyType> agencyTypes, List<Personality> 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
Expand All @@ -53,7 +51,7 @@ public List<Activity> findByAgencyAndPersonalities(long offset, long limit, Agen
}

@Override
public List<Activity> findLikedActivities(Long userId, long offset, long limit, AgencyType agencyType, List<Personality> personalities) {
public List<Activity> findLikedActivities(Long userId, long offset, long limit, List<AgencyType> agencyTypes, List<Personality> personalities) {
BooleanBuilder builder = new BooleanBuilder();

// 사용자의 좋아하는 활동 ID 목록을 조회
Expand All @@ -72,8 +70,8 @@ public List<Activity> 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));
Expand All @@ -90,17 +88,15 @@ public List<Activity> findLikedActivities(Long userId, long offset, long limit,


@Override
public Long countActivities(AgencyType agencyType, List<Personality> personalities) {
public Long countActivities(List<AgencyType> agencyTypes, List<Personality> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgencyType> agencyTypes = activitiesReq.getAgencyTypes().stream()
.map(AgencyType::of)
.collect(Collectors.toList());
List<Personality> 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<Long> likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId);
Set<Long> likedActivityIdsSet = new HashSet<>(likedActivityIds);

List<Activity> activities = activityRepository.findByAgencyAndPersonalities(offset, limit, agencyType, personalities);
List<Activity> activities = activityRepository.findByAgencyAndPersonalities(offset, limit, agencyTypes, personalities);
List<ActivitySummaryRes> activitySummaries = activities.stream()
.map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId())))
.toList();
Expand All @@ -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<AgencyType> agencyTypes = activitiesReq.getAgencyTypes().stream()
.map(AgencyType::of)
.collect(Collectors.toList());
List<Personality> 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<Long> likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId);
Set<Long> likedActivityIdsSet = new HashSet<>(likedActivityIds);

List<Activity> activities = activityRepository.findLikedActivities(userId, offset, limit, agencyType, personalities);
List<Activity> activities = activityRepository.findLikedActivities(userId, offset, limit, agencyTypes, personalities);
List<ActivitySummaryRes> activitySummaries = activities.stream()
.map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId())))
.toList();
Expand Down

0 comments on commit 0c833c8

Please sign in to comment.