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

v2.0.3 #405

Merged
merged 4 commits into from
May 21, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/production_build_deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/arm64/v8
push: true
tags: ${{ steps.metadata.outputs.tags }}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -46,8 +45,10 @@ public FeedSliceResponse feedFindByPage(
@Operation(summary = "피드 탭 V2 (페이지네이션)", description = "피드 탭을 조회합니다.")
@GetMapping("/me/v2")
public Slice<FeedOneResponse> 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 = "피드 탭을 조회합니다.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -62,23 +61,23 @@ public FeedSliceResponse findFeed(int size, Long lastId, MissionVisibility visib
}

@Transactional(readOnly = true)
public Slice<FeedOneResponse> findFeedV2(FeedVisibility visibility, Pageable pageable) {
public Slice<FeedOneResponse> 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<FeedOneResponse> findAllFeedV2(Pageable pageable) {
return missionRecordRepository.findAllFetch(pageable).map(FeedOneResponse::from);
private Slice<FeedOneResponse> findAllFeedV2(int size, Long lastId) {
return missionRecordRepository.findAllFetch(size, lastId).map(FeedOneResponse::from);
}

private Slice<FeedOneResponse> findFollowingFeedV2(Pageable pageable) {
private Slice<FeedOneResponse> findFollowingFeedV2(int size, Long lastId) {
final Member currentMember = memberUtil.getCurrentMember();
List<Member> followingMembers = followService.getFollowingMembers(currentMember);

return missionRecordRepository
.findAllFetchByFollowings(pageable, followingMembers)
.findAllFetchByFollowings(size, lastId, followingMembers)
.map(FeedOneResponse::from);
}

Expand All @@ -95,8 +94,8 @@ public FeedSliceResponse findAllFeed(int size, Long lastId) {
public FeedSliceResponse findFollowerFeed(int size, Long lastId) {
final Member currentMember = memberUtil.getCurrentMember();
List<Member> sourceMembers = getSourceMembers(currentMember.getId());
System.out.println(sourceMembers.size());

sourceMembers.add(currentMember);
Slice<FeedOneResponse> feedAllByPage =
missionRecordRepository.findFeedAllByPage(size, lastId, sourceMembers);
return FeedSliceResponse.from(feedAllByPage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,7 +30,8 @@ List<FeedOneResponse> findFeedByVisibility(
Slice<FeedOneResponse> findFeedByVisibilityAndPage(
int size, Long lastId, List<Member> members, List<MissionVisibility> visibility);

Slice<MissionRecord> findAllFetch(Pageable pageable);
Slice<MissionRecord> findAllFetch(int size, Long lastId);

Slice<MissionRecord> findAllFetchByFollowings(Pageable pageable, List<Member> followingMembers);
Slice<MissionRecord> findAllFetchByFollowings(
int size, Long lastId, List<Member> followingMembers);
}
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public void deleteByMissionRecordId(Long missionRecordId) {
}

@Override
public Slice<MissionRecord> findAllFetch(Pageable pageable) {
public Slice<MissionRecord> findAllFetch(int size, Long lastId) {

List<MissionRecord> missionRecords =
jpaQueryFactory
Expand All @@ -180,18 +180,18 @@ public Slice<MissionRecord> 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<MissionRecord> findAllFetchByFollowings(
Pageable pageable, List<Member> followingMembers) {
int size, Long lastId, List<Member> followingMembers) {

List<MissionRecord> missionRecords =
jpaQueryFactory
Expand All @@ -200,15 +200,16 @@ public Slice<MissionRecord> 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) {
Expand Down Expand Up @@ -253,10 +254,10 @@ private Slice<FeedOneResponse> checkLastPage(int size, List<FeedOneResponse> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private void setFixture() {

// when
Pageable pageable = PageRequest.of(0, 10);
Slice<FeedOneResponse> response = feedService.findFeedV2(FeedVisibility.ALL, pageable);
Slice<FeedOneResponse> response = feedService.findFeedV2(FeedVisibility.ALL, 10, 5L);

// then
assertThat(response.getContent()).hasSize(4);
Expand All @@ -248,7 +248,7 @@ class 팔로잉_피드이면 {
// when
Pageable pageable = PageRequest.of(0, 10);
Slice<FeedOneResponse> response =
feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable);
feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 5L);

// then
assertThat(response.getContent()).hasSize(2);
Expand All @@ -263,7 +263,7 @@ class 팔로잉_피드이면 {
// when
Pageable pageable = PageRequest.of(0, 10);
Slice<FeedOneResponse> response =
feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable);
feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 5L);

// then
assertThat(response.getContent())
Expand All @@ -279,7 +279,7 @@ class 팔로잉_피드이면 {
// when
Pageable pageable = PageRequest.of(0, 10);
Slice<FeedOneResponse> response =
feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable);
feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 5L);

// then
// 2번 미션의 미션기록은 공개이므로 조회
Expand All @@ -301,7 +301,7 @@ class 팔로잉_피드이면 {
// when
Pageable pageable = PageRequest.of(0, 10);
Slice<FeedOneResponse> response =
feedService.findFeedV2(FeedVisibility.FOLLOWING, pageable);
feedService.findFeedV2(FeedVisibility.FOLLOWING, 10, 0L);

// then
assertThat(response.getContent())
Expand Down
Loading