Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : fetchJoin으로 인한 중복값으로 인해 페이징시목록이 제대로 호출되지 않는 버그 수정 #105

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@

public interface FeedExerciseJournalRepositoryCustom {

Page<FeedExerciseJournal> feedExerciseJournalLists(Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest);
Page<Long> feedExerciseJournalLists(Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest);

Page<FeedExerciseJournal> feedExerciseJournalListsByFollow(String email, Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest);
Page<Long> feedExerciseJournalListsByFollow(String email, Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest);

Page<FeedExerciseJournal> userFeedExerciseJournalLists(String nickname, Pageable pageable);
Page<Long> userFeedExerciseJournalLists(String nickname, Pageable pageable);

Page<FeedExerciseJournal> userFeedExerciseJournalCollectionLists(String nickname, Pageable pageable);
Page<Long> userFeedExerciseJournalCollectionLists(String nickname, Pageable pageable);

Optional<FeedDetailResponse> feedDetail(Long feedJournalId);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ogjg.daitgym.feed.repository;


import com.ogjg.daitgym.domain.feed.FeedExerciseJournal;
import com.ogjg.daitgym.feed.dto.request.FeedSearchConditionRequest;
import com.ogjg.daitgym.feed.dto.response.FeedDetailResponse;
import com.ogjg.daitgym.feed.dto.response.QFeedDetailResponse;
Expand Down Expand Up @@ -37,11 +36,11 @@ public class FeedExerciseJournalRepositoryImpl implements FeedExerciseJournalRep
* 피드의 운동일지 전체 목록 검색 query
*/
@Override
public Page<FeedExerciseJournal> feedExerciseJournalLists(
public Page<Long> feedExerciseJournalLists(
Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest
) {
List<FeedExerciseJournal> journalLists = jpaQueryFactory.select(
feedExerciseJournal
List<Long> journalLists = jpaQueryFactory.select(
feedExerciseJournal.id
).from(feedExerciseJournal)
.join(feedExerciseJournal.exerciseJournal, exerciseJournal).fetchJoin()
.leftJoin(exerciseList).on(exerciseJournal.id.eq(exerciseList.exerciseJournal.id)).fetchJoin()
Expand All @@ -51,6 +50,7 @@ public Page<FeedExerciseJournal> feedExerciseJournalLists(
feedExerciseJournal.exerciseJournal.split.eq(feedSearchConditionRequest.getSplit()),
exercisePartEq(feedSearchConditionRequest.getPart(), exercisePart.part)
).orderBy(feedExerciseJournal.createdAt.desc())
.distinct()
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand All @@ -75,11 +75,11 @@ public Page<FeedExerciseJournal> feedExerciseJournalLists(
* 내가 팔로우의 target 사람들의 list를 가져와서 피드와 join
* */
@Override
public Page<FeedExerciseJournal> feedExerciseJournalListsByFollow(
public Page<Long> feedExerciseJournalListsByFollow(
String email, Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest
) {

List<FeedExerciseJournal> followerFeedJournalLists = jpaQueryFactory.select(feedExerciseJournal)
List<Long> followerFeedJournalLists = jpaQueryFactory.select(feedExerciseJournal.id)
.from(follow)
.where(follow.follower.email.eq(email))
.join(feedExerciseJournal).on(feedExerciseJournal.exerciseJournal.user.email.eq(follow.target.email)).fetchJoin()
Expand All @@ -92,6 +92,7 @@ public Page<FeedExerciseJournal> feedExerciseJournalListsByFollow(
exercisePartEq(feedSearchConditionRequest.getPart(), exercisePart.part)
)
.orderBy(feedExerciseJournal.createdAt.desc())
.distinct()
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand All @@ -116,14 +117,15 @@ public Page<FeedExerciseJournal> feedExerciseJournalListsByFollow(
/**
* 유저 페이지 피드 운동일지 목록 가져오기
*/
public Page<FeedExerciseJournal> userFeedExerciseJournalLists(
public Page<Long> userFeedExerciseJournalLists(
String nickname, Pageable pageable
) {
List<FeedExerciseJournal> userFeedJournalLists = jpaQueryFactory.select(feedExerciseJournal)
List<Long> userFeedJournalLists = jpaQueryFactory.select(feedExerciseJournal.id)
.from(user)
.where(user.nickname.eq(nickname))
.join(feedExerciseJournal).on(user.email.eq(feedExerciseJournal.exerciseJournal.user.email)).fetchJoin()
.orderBy(feedExerciseJournal.createdAt.desc())
.distinct()
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.fetch();
Expand All @@ -139,10 +141,10 @@ public Page<FeedExerciseJournal> userFeedExerciseJournalLists(
/**
* 유저 페이지 피드 운동일지 컬렉션 가져오기
*/
public Page<FeedExerciseJournal> userFeedExerciseJournalCollectionLists(
public Page<Long> userFeedExerciseJournalCollectionLists(
String nickname, Pageable pageable
) {
List<FeedExerciseJournal> userFeedJournalCollections = jpaQueryFactory.select(feedExerciseJournal)
List<Long> userFeedJournalCollections = jpaQueryFactory.select(feedExerciseJournal.id)
.from(feedExerciseJournalCollection)
.join(user).on(feedExerciseJournalCollection.user.email.eq(user.email)).fetchJoin()
.where(user.nickname.eq(nickname))
Expand All @@ -151,6 +153,7 @@ public Page<FeedExerciseJournal> userFeedExerciseJournalCollectionLists(
.orderBy(feedExerciseJournal.createdAt.desc())
.offset(pageable.getOffset())
.limit(pageable.getPageSize())
.distinct()
.fetch();

JPAQuery<Long> countQuery = jpaQueryFactory.select(feedExerciseJournal.count())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import com.ogjg.daitgym.journal.repository.journal.ExerciseJournalRepository;
import com.ogjg.daitgym.journal.service.ExerciseJournalHelper;
import com.ogjg.daitgym.like.feedExerciseJournal.repository.FeedExerciseJournalLikeRepository;
import com.ogjg.daitgym.user.service.UserHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
Expand All @@ -39,6 +40,7 @@ public class FeedExerciseJournalService {
private final FeedExerciseJournalLikeRepository feedExerciseJournalLikeRepository;
private final FeedExerciseJournalCollectionRepository feedExerciseJournalCollectionRepository;
private final FeedJournalHelper feedJournalHelper;
private final UserHelper userHelper;
private final ExerciseJournalHelper exerciseJournalHelper;

/**
Expand All @@ -50,7 +52,7 @@ public class FeedExerciseJournalService {
public FeedExerciseJournalListResponse feedExerciseJournalLists(
Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest
) {
Page<FeedExerciseJournal> feedExerciseJournals =
Page<Long> feedExerciseJournals =
feedExerciseJournalRepository.feedExerciseJournalLists(pageable, feedSearchConditionRequest);

List<FeedExerciseJournalListDto> content =
Expand All @@ -70,7 +72,7 @@ public FeedExerciseJournalListResponse feedExerciseJournalLists(
public FeedExerciseJournalListResponse followFeedJournalLists(
String email, Pageable pageable, FeedSearchConditionRequest feedSearchConditionRequest
) {
Page<FeedExerciseJournal> feedExerciseJournals =
Page<Long> feedExerciseJournals =
feedExerciseJournalRepository.feedExerciseJournalListsByFollow(email, pageable, feedSearchConditionRequest);

List<FeedExerciseJournalListDto> content =
Expand All @@ -93,7 +95,7 @@ public void feedExerciseJournalScrap(String email, Long feedExerciseJournalId) {

feedExerciseJournalCollectionRepository.save(
new FeedExerciseJournalCollection(
feedJournalHelper.findUserByEmail(email),
userHelper.findUserByEmail(email),
feedJournalHelper.findFeedJournalById(feedExerciseJournalId)
)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@ public FeedExerciseJournal findFeedJournalByJournal(ExerciseJournal exerciseJour
* 피드 운동일지 상세보기를 Dto로 변환
*/
public List<FeedExerciseJournalListDto> feedExerciseJournalsChangeFeedExerciseJournalsDto(
Page<FeedExerciseJournal> feedExerciseJournals
Page<Long> feedExerciseJournalsId
) {
return feedExerciseJournals.getContent()
return feedExerciseJournalsId.getContent()
.stream()
.map(feedExerciseJournal -> new FeedExerciseJournalListDto(
feedExerciseJournal.getId(),
feedExerciseJournalLikes(feedExerciseJournal.getId()),
feedExerciseJournalScrapCounts(feedExerciseJournal.getId()),
feedCoverImage(findFeedExerciseJournalImagesByFeedExerciseJournal(feedExerciseJournal))
.map(feedExerciseJournalId -> new FeedExerciseJournalListDto(
feedExerciseJournalId,
feedExerciseJournalLikes(feedExerciseJournalId),
feedExerciseJournalScrapCounts(feedExerciseJournalId),
feedCoverImage(findFeedExerciseJournalImagesByFeedExerciseJournal(
feedExerciseJournalRepository.findById(feedExerciseJournalId).orElseThrow(NotFoundFeedJournal::new)
))
)).toList();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.ogjg.daitgym.feed.service;

import com.ogjg.daitgym.domain.feed.FeedExerciseJournal;
import com.ogjg.daitgym.feed.dto.response.FeedExerciseJournalListDto;
import com.ogjg.daitgym.feed.dto.response.FeedExerciseJournalListResponse;
import com.ogjg.daitgym.feed.repository.FeedExerciseJournalRepository;
Expand All @@ -26,7 +25,7 @@ public class UserFeedExerciseJournalService {
public FeedExerciseJournalListResponse userFeedExerciseJournalLists(
String nickname, Pageable pageable
) {
Page<FeedExerciseJournal> userFeedExerciseJournals =
Page<Long> userFeedExerciseJournals =
feedExerciseJournalRepository.userFeedExerciseJournalLists(nickname, pageable);

List<FeedExerciseJournalListDto> content =
Expand All @@ -44,7 +43,7 @@ public FeedExerciseJournalListResponse userFeedExerciseJournalLists(
public FeedExerciseJournalListResponse userFeedExerciseJournalCollectionLists(
String nickname, Pageable pageable
) {
Page<FeedExerciseJournal> userFeedJournalCollections =
Page<Long> userFeedJournalCollections =
feedExerciseJournalRepository.userFeedExerciseJournalCollectionLists(nickname, pageable);

List<FeedExerciseJournalListDto> content =
Expand Down