Skip to content

Commit

Permalink
Merge pull request #217 from Team-TenTen/fix/space/pagination
Browse files Browse the repository at this point in the history
Fix/space/pagination  -  ์ŠคํŽ˜์ด์Šค ํ•„ํ„ฐ ์กฐํšŒ API NPE ํ•ด๊ฒฐ.
  • Loading branch information
young970 authored Jan 31, 2024
2 parents 4ffb84f + 5588b1f commit 44066f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import io.swagger.v3.oas.annotations.media.Schema;

public record PublicSpacesFindWithFilterApiRequest(
@Schema(title = "๋งˆ์ง€๋ง‰ favoriteCount", example = "1")
@Schema(title = "๋งˆ์ง€๋ง‰ favoriteCount", example = "0")
Long lastFavoriteCount,

@Schema(title = "๋งˆ์ง€๋ง‰ spaceId", example = "1")
@Schema(title = "๋งˆ์ง€๋ง‰ spaceId", example = "62")
Long lastSpaceId,

@Schema(title = "ํŽ˜์ด์ง€ ํฌ๊ธฐ", example = "10")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.tenten.linkhub.domain.space.repository.common.mapper;

import com.tenten.linkhub.domain.space.common.SpaceCursorPageRequest;
import com.tenten.linkhub.domain.space.common.SpaceCursorSlice;
import com.tenten.linkhub.domain.space.model.space.Space;
import com.tenten.linkhub.domain.space.model.space.SpaceImage;
import com.tenten.linkhub.domain.space.repository.common.dto.SpaceAndOwnerNickName;
import com.tenten.linkhub.domain.space.repository.common.dto.SpaceAndSpaceImageOwnerNickName;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@Component
Expand All @@ -29,4 +33,16 @@ public List<SpaceAndSpaceImageOwnerNickName> toSpaceAndSpaceImageOwnerNickNames(
.collect(Collectors.toList());
}

public SpaceCursorSlice<SpaceAndSpaceImageOwnerNickName> toSpaceCursorSlice(List<SpaceAndSpaceImageOwnerNickName> contents, SpaceCursorPageRequest pageable, boolean hasNext){
Space lastSpace = contents.isEmpty() ? null : contents.get(contents.size() - 1).space();

return SpaceCursorSlice.of(
Objects.isNull(lastSpace) ? null : lastSpace.getFavoriteCount(),
Objects.isNull(lastSpace) ? null : lastSpace.getId(),
pageable.pageSize(),
hasNext,
contents
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

import static com.tenten.linkhub.domain.member.model.QMember.member;
import static com.tenten.linkhub.domain.space.model.space.QSpace.space;
Expand Down Expand Up @@ -62,15 +63,7 @@ public SpaceCursorSlice<SpaceAndSpaceImageOwnerNickName> findPublicSpacesJoinSpa
hasNext = true;
}

Space lastSpace = contents.get(contents.size() - 1).space();

return SpaceCursorSlice.of(
lastSpace.getFavoriteCount(),
lastSpace.getId(),
pageable.pageSize(),
hasNext,
contents
);
return mapper.toSpaceCursorSlice(contents, pageable, hasNext);
}

public Slice<SpaceAndSpaceImageOwnerNickName> searchPublicSpacesJoinSpaceImageByCondition(QueryCondition condition) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,9 @@ void findMemberSpacesByQuery_emptyKeyWord_emptyFilter() {
List<SpacesFindByQueryResponse> content = response.responses().getContent();

assertThat(content.size()).isEqualTo(2);
assertThat(content.get(1).spaceName()).isEqualTo("์„ธ๋ฒˆ์งธ ์ŠคํŽ˜์ด์Šค");
assertThat(content.get(1).spaceImagePath()).isEqualTo("https://testimage3");
assertThat(content.get(1).ownerNickName()).isEqualTo("๋ฐฑ๋‘ฅ์ด");
assertThat(content.get(0).spaceName()).isEqualTo("์„ธ๋ฒˆ์งธ ์ŠคํŽ˜์ด์Šค");
assertThat(content.get(0).spaceImagePath()).isEqualTo("https://testimage3");
assertThat(content.get(0).ownerNickName()).isEqualTo("๋ฐฑ๋‘ฅ์ด");
}

@Test
Expand All @@ -176,12 +176,11 @@ void findMemberSpacesByQuery_emptyKeyWord_emptyFilter_findMySpaces() {
List<SpacesFindByQueryResponse> content = response.responses().getContent();

assertThat(content.size()).isEqualTo(2);
assertThat(content.get(0).spaceName()).isEqualTo("์ฒซ๋ฒˆ์งธ ์ŠคํŽ˜์ด์Šค");
assertThat(content.get(0).description()).isEqualTo("์ฒซ๋ฒˆ์งธ ์ŠคํŽ˜์ด์Šค ์†Œ๊ฐœ๊ธ€");
assertThat(content.get(0).category()).isEqualTo(Category.KNOWLEDGE_ISSUE_CAREER);
assertThat(content.get(0).spaceImagePath()).isEqualTo("https://testimage1");
assertThat(content.get(0).spaceName()).isEqualTo("๋‘๋ฒˆ์งธ ์ŠคํŽ˜์ด์Šค");
assertThat(content.get(0).spaceImagePath()).isEqualTo("https://testimage2");
assertThat(content.get(0).ownerNickName()).isEqualTo("์ž ์ž๋Š” ์‚ฌ์ž์˜ ์ฝงํ„ธ");
assertThat(content.get(1).spaceName()).isEqualTo("๋‘๋ฒˆ์งธ ์ŠคํŽ˜์ด์Šค");
assertThat(content.get(1).spaceName()).isEqualTo("์ฒซ๋ฒˆ์งธ ์ŠคํŽ˜์ด์Šค");
assertThat(content.get(1).spaceImagePath()).isEqualTo("https://testimage1");
assertThat(content.get(1).ownerNickName()).isEqualTo("์ž ์ž๋Š” ์‚ฌ์ž์˜ ์ฝงํ„ธ");
}

Expand Down

0 comments on commit 44066f3

Please sign in to comment.