From 3c04983e38b58fafb57c3a3b49eb524b00bd9b08 Mon Sep 17 00:00:00 2001 From: nohy6630 Date: Thu, 23 May 2024 01:26:05 +0900 Subject: [PATCH] =?UTF-8?q?Fix:=20=EB=B0=B0=EC=9B=80=EB=82=98=EB=88=84?= =?UTF-8?q?=EA=B8=B0=20=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=EC=8B=9C=20?= =?UTF-8?q?=EB=B3=B8=EC=9D=B8=20=EA=B2=8C=EC=8B=9C=EA=B8=80=EC=9D=80=20?= =?UTF-8?q?=EC=A0=9C=EC=99=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../repository/custom/ExperienceRepositoryCustom.java | 4 ++-- .../repository/custom/ExperienceRepositoryImpl.java | 10 +++++++--- .../domain/experience/service/ExperienceService.java | 10 ++++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryCustom.java b/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryCustom.java index 0ef94dc..59c2051 100644 --- a/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryCustom.java +++ b/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryCustom.java @@ -6,8 +6,8 @@ import java.util.List; public interface ExperienceRepositoryCustom { - List findExperiencesOrderByLatest(long offset,long limit, String category); - List findExperiencesOrderByReview(long offset,long limit, String category); + List findExperiencesOrderByLatest(long offset,long limit, String category, User user); + List findExperiencesOrderByReview(long offset,long limit, String category, User user); Long countExperiences(String category); diff --git a/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryImpl.java b/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryImpl.java index 02a0b62..7de966d 100644 --- a/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryImpl.java +++ b/src/main/java/com/meetup/teame/backend/domain/experience/repository/custom/ExperienceRepositoryImpl.java @@ -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; @@ -18,10 +19,12 @@ public class ExperienceRepositoryImpl implements ExperienceRepositoryCustom { private final JPAQueryFactory jpaQueryFactory; @Override - public List findExperiencesOrderByLatest(long offset, long limit, String category) { + public List 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) @@ -34,8 +37,9 @@ public List findExperiencesOrderByLatest(long offset, long limit, St } @Override - public List findExperiencesOrderByReview(long offset, long limit, String category) { + public List 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 diff --git a/src/main/java/com/meetup/teame/backend/domain/experience/service/ExperienceService.java b/src/main/java/com/meetup/teame/backend/domain/experience/service/ExperienceService.java index 8f60af8..1e5669f 100644 --- a/src/main/java/com/meetup/teame/backend/domain/experience/service/ExperienceService.java +++ b/src/main/java/com/meetup/teame/backend/domain/experience/service/ExperienceService.java @@ -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(); @@ -33,9 +39,9 @@ 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); }