Skip to content

Commit

Permalink
Merge pull request #78 from Kusitms-29th-Meetup-TeamE/fix/74/main-page
Browse files Browse the repository at this point in the history
Fix: 활동 온보딩 필터링
  • Loading branch information
Jeongho427 authored May 23, 2024
2 parents c61d358 + cb674cd commit 6fdb7f5
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,17 @@ public List<Activity> findActivitiesForUser(User user) {
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 (personalities != null && !personalities.isEmpty()) {
builder.or(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
.selectFrom(activity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public class ActivityService {

//특정 활동 상제 정보 response dto화
public ActivityDetailsRes getActivityDetails(Long activityId) {
Long userId = SecurityContextProvider.getAuthenticatedUserId();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));

Activity activity = findActivityById(activityId);
return ActivityDetailsRes.of(activity);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
@Getter
@Builder
public class ReadExperienceDetailRes {
private Long id;
private String imageUrl;
private String name;
private Long age;
Expand All @@ -37,6 +38,7 @@ public static ReadExperienceDetailRes of(Experience experience) {
.toList();

return ReadExperienceDetailRes.builder()
.id(experience.getId())
.imageUrl(user.getImageUrl())
.name(user.getName())
.age(user.getAge())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import java.util.List;

public interface ExperienceRepositoryCustom {
List<Experience> findExperiencesOrderByLatest(long offset,long limit, String category);
List<Experience> findExperiencesOrderByReview(long offset,long limit, String category);
List<Experience> findExperiencesOrderByLatest(long offset,long limit, String category, User user);
List<Experience> findExperiencesOrderByReview(long offset,long limit, String category, User user);

Long countExperiences(String category);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.meetup.teame.backend.domain.experience.entity.ExperienceType;
import com.meetup.teame.backend.domain.experience.entity.QExperience;
import com.meetup.teame.backend.domain.user.entity.QUser;
import com.meetup.teame.backend.domain.user.entity.User;
import com.querydsl.core.BooleanBuilder;
import com.querydsl.jpa.impl.JPAQueryFactory;
import lombok.RequiredArgsConstructor;
Expand All @@ -18,10 +19,12 @@ public class ExperienceRepositoryImpl implements ExperienceRepositoryCustom {
private final JPAQueryFactory jpaQueryFactory;

@Override
public List<Experience> findExperiencesOrderByLatest(long offset, long limit, String category) {
public List<Experience> findExperiencesOrderByLatest(long offset, long limit, String category, User me) {
BooleanBuilder builder = new BooleanBuilder();
if (category != null)
builder.and(experience.user.ne(me));
if (category != null) {
builder.and(experience.type.eq(ExperienceType.of(category)));
}
return jpaQueryFactory
.selectFrom(experience)
.join(experience.user, user)
Expand All @@ -34,8 +37,9 @@ public List<Experience> findExperiencesOrderByLatest(long offset, long limit, St
}

@Override
public List<Experience> findExperiencesOrderByReview(long offset, long limit, String category) {
public List<Experience> findExperiencesOrderByReview(long offset, long limit, String category, User me) {
BooleanBuilder builder = new BooleanBuilder();
builder.and(experience.user.ne(me));
if (category != null)
builder.and(experience.type.eq(ExperienceType.of(category)));
return jpaQueryFactory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ public class ExperienceService {
private static final int EXPERIENCE_PAGE_SIZE = 6;

public ReadExperiencesRes readExperiences(ReadExperiencesReq readExperiencesReq) {
Long userId = 50L;
if (!SecurityContextProvider.isAnonymousUser()) {
userId = SecurityContextProvider.getAuthenticatedUserId();
}
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
Long page = readExperiencesReq.getPage();
String sort = readExperiencesReq.getSort();
String category = readExperiencesReq.getCategory();
Expand All @@ -33,16 +39,15 @@ public ReadExperiencesRes readExperiences(ReadExperiencesReq readExperiencesReq)
category = null;
long pageCount = experienceRepository.countExperiences(category) / EXPERIENCE_PAGE_SIZE + 1;
if (sort.equals("latest"))
return ReadExperiencesRes.of(page, pageCount, experienceRepository.findExperiencesOrderByLatest(offset, limit, category));
return ReadExperiencesRes.of(page, pageCount, experienceRepository.findExperiencesOrderByLatest(offset, limit, category, user));
else if (sort.equals("review"))
return ReadExperiencesRes.of(page, pageCount, experienceRepository.findExperiencesOrderByReview(offset, limit, category));
return ReadExperiencesRes.of(page, pageCount, experienceRepository.findExperiencesOrderByReview(offset, limit, category, user));
else
throw new CustomException(ExceptionContent.BAD_REQUEST_SORT_TYPE);
}

public MyExperienceProfileRes readMyExperienceProfile() {
Long userId = SecurityContextProvider.getAuthenticatedUserId();
//todo 1+N문제 발생가능 테스트해보고 default_fetch_batch_size 적용
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER));
return MyExperienceProfileRes.of(user);
Expand Down

0 comments on commit 6fdb7f5

Please sign in to comment.