diff --git a/src/main/java/com/depromeet/domain/feed/api/FeedController.java b/src/main/java/com/depromeet/domain/feed/api/FeedController.java index 62a24f81..8b9b48a7 100644 --- a/src/main/java/com/depromeet/domain/feed/api/FeedController.java +++ b/src/main/java/com/depromeet/domain/feed/api/FeedController.java @@ -10,7 +10,6 @@ import io.swagger.v3.oas.annotations.tags.Tag; import java.util.List; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; @@ -46,8 +45,10 @@ public FeedSliceResponse feedFindByPage( @Operation(summary = "피드 탭 V2 (페이지네이션)", description = "피드 탭을 조회합니다.") @GetMapping("/me/v2") public Slice feedFindByPageV2( - @RequestParam(required = false) FeedVisibility visibility, Pageable pageable) { - return feedService.findFeedV2(visibility, pageable); + @RequestParam int size, + @RequestParam(required = false) Long lastId, + @RequestParam(required = false) FeedVisibility visibility) { + return feedService.findFeedV2(visibility, size, lastId); } @Operation(summary = "프로필 피드", description = "피드 탭을 조회합니다.") diff --git a/src/main/java/com/depromeet/domain/feed/application/FeedService.java b/src/main/java/com/depromeet/domain/feed/application/FeedService.java index bebf1ab2..127274ce 100644 --- a/src/main/java/com/depromeet/domain/feed/application/FeedService.java +++ b/src/main/java/com/depromeet/domain/feed/application/FeedService.java @@ -19,7 +19,6 @@ import java.util.ArrayList; import java.util.List; import lombok.RequiredArgsConstructor; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -62,23 +61,23 @@ public FeedSliceResponse findFeed(int size, Long lastId, MissionVisibility visib } @Transactional(readOnly = true) - public Slice findFeedV2(FeedVisibility visibility, Pageable pageable) { + public Slice findFeedV2(FeedVisibility visibility, int size, Long lastId) { if (visibility == FeedVisibility.ALL) { - return findAllFeedV2(pageable); + return findAllFeedV2(size, lastId); } - return findFollowingFeedV2(pageable); + return findFollowingFeedV2(size, lastId); } - private Slice findAllFeedV2(Pageable pageable) { - return missionRecordRepository.findAllFetch(pageable).map(FeedOneResponse::from); + private Slice findAllFeedV2(int size, Long lastId) { + return missionRecordRepository.findAllFetch(size, lastId).map(FeedOneResponse::from); } - private Slice findFollowingFeedV2(Pageable pageable) { + private Slice findFollowingFeedV2(int size, Long lastId) { final Member currentMember = memberUtil.getCurrentMember(); List followingMembers = followService.getFollowingMembers(currentMember); return missionRecordRepository - .findAllFetchByFollowings(pageable, followingMembers) + .findAllFetchByFollowings(size, lastId, followingMembers) .map(FeedOneResponse::from); } @@ -95,8 +94,8 @@ public FeedSliceResponse findAllFeed(int size, Long lastId) { public FeedSliceResponse findFollowerFeed(int size, Long lastId) { final Member currentMember = memberUtil.getCurrentMember(); List sourceMembers = getSourceMembers(currentMember.getId()); + System.out.println(sourceMembers.size()); - sourceMembers.add(currentMember); Slice feedAllByPage = missionRecordRepository.findFeedAllByPage(size, lastId, sourceMembers); return FeedSliceResponse.from(feedAllByPage); diff --git a/src/main/java/com/depromeet/domain/mission/application/MissionService.java b/src/main/java/com/depromeet/domain/mission/application/MissionService.java index 22f64f54..33d48249 100644 --- a/src/main/java/com/depromeet/domain/mission/application/MissionService.java +++ b/src/main/java/com/depromeet/domain/mission/application/MissionService.java @@ -19,6 +19,7 @@ import java.time.Duration; import java.time.LocalDate; import java.time.LocalDateTime; +import java.time.Period; import java.util.ArrayList; import java.util.Comparator; import java.util.List; @@ -283,7 +284,10 @@ private Mission createMissionEntity(MissionCreateRequest missionCreateRequest) { missionCreateRequest.category(), missionCreateRequest.visibility(), startedAt, - startedAt.plus(missionCreateRequest.period().getPeriod()), + startedAt.plus( + missionCreateRequest.period() == null + ? Period.ofWeeks(2) + : missionCreateRequest.period().getPeriod()), missionCreateRequest.remindAt(), member); } diff --git a/src/main/java/com/depromeet/domain/mission/dto/request/MissionCreateRequest.java b/src/main/java/com/depromeet/domain/mission/dto/request/MissionCreateRequest.java index 1fc73f38..cddad29e 100644 --- a/src/main/java/com/depromeet/domain/mission/dto/request/MissionCreateRequest.java +++ b/src/main/java/com/depromeet/domain/mission/dto/request/MissionCreateRequest.java @@ -20,6 +20,6 @@ public record MissionCreateRequest( @NotNull @Schema(description = "미션 카테고리", defaultValue = "STUDY") MissionCategory category, @NotNull @Schema(description = "미션 공개여부", defaultValue = "ALL") MissionVisibility visibility, - @NotNull @Schema(description = "미션 기한", defaultValue = "TWO_WEEKS") MissionPeriod period, + @Schema(description = "미션 기한", defaultValue = "TWO_WEEKS") MissionPeriod period, @Schema(description = "미션 리마인드 알림 시간", defaultValue = "00:50:00", type = "string") LocalTime remindAt) {} diff --git a/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryCustom.java b/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryCustom.java index 4c674b07..a8abdfe7 100644 --- a/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryCustom.java +++ b/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryCustom.java @@ -6,7 +6,6 @@ import com.depromeet.domain.missionRecord.domain.MissionRecord; import java.time.YearMonth; import java.util.List; -import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Slice; public interface MissionRecordRepositoryCustom { @@ -31,7 +30,8 @@ List findFeedByVisibility( Slice findFeedByVisibilityAndPage( int size, Long lastId, List members, List visibility); - Slice findAllFetch(Pageable pageable); + Slice findAllFetch(int size, Long lastId); - Slice findAllFetchByFollowings(Pageable pageable, List followingMembers); + Slice findAllFetchByFollowings( + int size, Long lastId, List followingMembers); } diff --git a/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryImpl.java b/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryImpl.java index f5a81ebb..fc3925f5 100644 --- a/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryImpl.java +++ b/src/main/java/com/depromeet/domain/missionRecord/dao/MissionRecordRepositoryImpl.java @@ -168,7 +168,7 @@ public void deleteByMissionRecordId(Long missionRecordId) { } @Override - public Slice findAllFetch(Pageable pageable) { + public Slice findAllFetch(int size, Long lastId) { List missionRecords = jpaQueryFactory @@ -180,18 +180,18 @@ public Slice findAllFetch(Pageable pageable) { .leftJoin(missionRecord.reactions, reaction) .fetchJoin() .distinct() - .offset(pageable.getOffset()) - .limit(pageable.getPageSize() + 1L) + .where(ltMissionRecordId(lastId)) + .limit((long) size + 1) .fetch(); - boolean hasNext = getHasNext(missionRecords, pageable); + boolean hasNext = getHasNext(missionRecords, size); - return new SliceImpl<>(missionRecords, pageable, hasNext); + return new SliceImpl<>(missionRecords, Pageable.ofSize(size), hasNext); } @Override public Slice findAllFetchByFollowings( - Pageable pageable, List followingMembers) { + int size, Long lastId, List followingMembers) { List missionRecords = jpaQueryFactory @@ -200,15 +200,16 @@ public Slice findAllFetchByFollowings( .fetchJoin() .join(mission.member, member) .fetchJoin() - .where(missionRecord.mission.member.in(followingMembers)) + .where( + ltMissionRecordId(lastId), + missionRecord.mission.member.in(followingMembers)) .where(mission.visibility.in(List.of(ALL, FOLLOWER))) - .offset(pageable.getOffset()) - .limit(pageable.getPageSize() + 1L) + .limit((long) size + 1) .fetch(); - boolean hasNext = getHasNext(missionRecords, pageable); + boolean hasNext = getHasNext(missionRecords, size); - return new SliceImpl<>(missionRecords, pageable, hasNext); + return new SliceImpl<>(missionRecords, Pageable.ofSize(size), hasNext); } private BooleanExpression missionIdEq(Long missionId) { @@ -253,10 +254,10 @@ private Slice checkLastPage(int size, List res return new SliceImpl<>(result, pageable, hasNext); } - private boolean getHasNext(List list, Pageable pageable) { + private boolean getHasNext(List list, int size) { boolean hasNext = false; - if (list.size() > pageable.getPageSize()) { - list.remove(pageable.getPageSize()); + if (list.size() > size) { + list.remove(size); hasNext = true; } return hasNext; diff --git a/src/test/java/com/depromeet/domain/feed/application/FeedServiceTest.java b/src/test/java/com/depromeet/domain/feed/application/FeedServiceTest.java index a772bd7b..ebd98968 100644 --- a/src/test/java/com/depromeet/domain/feed/application/FeedServiceTest.java +++ b/src/test/java/com/depromeet/domain/feed/application/FeedServiceTest.java @@ -230,7 +230,7 @@ private void setFixture() { // when Pageable pageable = PageRequest.of(0, 10); - Slice response = feedService.findFeedV2(FeedVisibility.ALL, pageable); + Slice response = feedService.findFeedV2(FeedVisibility.ALL, 10, 5L); // then assertThat(response.getContent()).hasSize(4); @@ -248,7 +248,7 @@ class 팔로잉_피드이면 { // when Pageable pageable = PageRequest.of(0, 10); Slice response = - feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable); + feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 5L); // then assertThat(response.getContent()).hasSize(2); @@ -263,7 +263,7 @@ class 팔로잉_피드이면 { // when Pageable pageable = PageRequest.of(0, 10); Slice response = - feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable); + feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 5L); // then assertThat(response.getContent()) @@ -279,7 +279,7 @@ class 팔로잉_피드이면 { // when Pageable pageable = PageRequest.of(0, 10); Slice response = - feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable); + feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 5L); // then // 2번 미션의 미션기록은 공개이므로 조회 @@ -301,7 +301,7 @@ class 팔로잉_피드이면 { // when Pageable pageable = PageRequest.of(0, 10); Slice response = - feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable); + feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 0L); // then assertThat(response.getContent())