Skip to content

Commit

Permalink
Fix: 활동 목록 온보딩 반영 및 익명 유저 사용 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeongho427 committed May 22, 2024
1 parent ddb87be commit 77d9eff
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public interface ActivityRepositoryCustom {
List<Activity> findActivitiesForUser(User user);

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ public List<Activity> findActivitiesForUser(User user) {
}

@Override
public List<Activity> findByAgencyAndPersonalities(long offset, long limit, List<AgencyType> agencyTypes, List<Personality> personalities) {
public List<Activity> findByAgencyAndPersonalities(long offset, long limit, User user, List<AgencyType> agencyTypes, List<Personality> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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;
Expand All @@ -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<Long> likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId);
Set<Long> likedActivityIdsSet = new HashSet<>(likedActivityIds);

List<Activity> activities = activityRepository.findByAgencyAndPersonalities(offset, limit, agencyTypes, personalities);
List<Activity> activities = activityRepository.findByAgencyAndPersonalities(offset, limit, user, agencyTypes, personalities);

long pageCount = (activities.size() + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE; // 전체 페이지 수 계산


List<ActivitySummaryRes> activitySummaries = activities.stream()
.map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId())))
.toList();
Expand All @@ -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<Long> likedActivityIds = activityLikeRepository.findLikedActivityIdsByUserId(userId);
Set<Long> likedActivityIdsSet = new HashSet<>(likedActivityIds);

long pageCount = (likedActivityIds.size() + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE;

List<Activity> activities = activityRepository.findLikedActivities(userId, offset, limit, agencyTypes, personalities);

long pageCount = (activities.size() + ACTIVITY_PAGE_SIZE - 1) / ACTIVITY_PAGE_SIZE;

List<ActivitySummaryRes> activitySummaries = activities.stream()
.map(activity -> ActivitySummaryRes.of(activity, likedActivityIdsSet.contains(activity.getId())))
.toList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
"/send-email",
"/register",
"/users/main",
"/activities",
"/swagger-ui/**",
"/swagger-resources/**",
"/v3/api-docs/**",
Expand Down

0 comments on commit 77d9eff

Please sign in to comment.