-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEFACTOR] Story 전체 조회 코드 리팩토링
- Loading branch information
Showing
6 changed files
with
106 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 3 additions & 31 deletions
34
src/main/java/com/owori/domain/story/dto/response/StoryPagingResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,19 @@ | ||
package com.owori.domain.story.dto.response; | ||
|
||
import com.owori.domain.story.entity.Story; | ||
import com.owori.domain.story.mapper.StoryMapper; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public class StoryPagingResponse { | ||
private static final StoryMapper storyMapper = new StoryMapper(); | ||
private static final Integer LAST_PAGE = -1; | ||
|
||
private List<FindAllStoryResponse> stories = new ArrayList<>(); | ||
private Integer nextPage; | ||
private Integer lastPage; | ||
|
||
|
||
|
||
public static StoryPagingResponse of(Page<Story> pageStory){ | ||
if(!pageStory.hasNext()){ | ||
return StoryPagingResponse.newLastScroll(pageStory.getContent(), pageStory.getTotalPages() - 1); | ||
} | ||
return StoryPagingResponse.newPageHasNext(pageStory.getContent(), pageStory.getTotalPages() - 1, pageStory.getPageable().getPageNumber() + 1); | ||
} | ||
|
||
private static StoryPagingResponse newPageHasNext(List<Story> stories, Integer lastPage, Integer nextPage) { | ||
return new StoryPagingResponse(getContents(stories), lastPage, nextPage); | ||
} | ||
|
||
private static StoryPagingResponse newLastScroll(List<Story> stories, Integer lastPage) { | ||
return newPageHasNext(stories, lastPage, LAST_PAGE); | ||
} | ||
|
||
private static List<FindAllStoryResponse> getContents(List<Story> stories){ | ||
return stories.stream().map(story -> storyMapper.toFindAllStoryResponse(story)).toList(); | ||
} | ||
|
||
|
||
private boolean hasNext; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.