Skip to content

Commit

Permalink
refactor: pathParams 에서 limit + 1 되도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
shb03323 committed Oct 5, 2023
1 parent bf9f7a5 commit ab0172f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@
@Service
public class RunnerPostQueryService {

private static final int ADDITIONAL_QUERY_DATA_COUNT = 1;

private final RunnerPostQueryRepository runnerPostQueryRepository;
private final RunnerPostPageRepository runnerPostPageRepository;
private final RunnerPostTagQueryRepository runnerPostTagQueryRepository;
Expand All @@ -44,8 +42,7 @@ public PageResponse<RunnerPostResponse.Simple> pageRunnerPostByTagNameAndReviewS
final PageParams pageParams,
final ReviewStatus reviewStatus
) {
final int queryCount = pageParams.limit() + ADDITIONAL_QUERY_DATA_COUNT;
final List<RunnerPost> runnerPosts = runnerPostPageRepository.pageByReviewStatusAndTagReducedName(pageParams.cursor(), queryCount, TagReducedName.nullableInstance(tagName), reviewStatus);
final List<RunnerPost> runnerPosts = runnerPostPageRepository.pageByReviewStatusAndTagReducedName(pageParams.cursor(), pageParams.getLimitForQuery(), TagReducedName.nullableInstance(tagName), reviewStatus);
final List<RunnerPostTag> runnerPostTags = runnerPostPageRepository.findRunnerPostTagsByRunnerPosts(runnerPosts);
final RunnerPostsApplicantCount runnerPostsApplicantCount = readRunnerPostsApplicantCount(runnerPosts);
final List<RunnerPostResponse.Simple> responses = runnerPosts.stream()
Expand All @@ -71,11 +68,10 @@ private List<RunnerPost> pageRunnerPostFromSupporterByReviewStatus(final PagePar
final Long supporterId,
final ReviewStatus reviewStatus
) {
final int queryCount = pageParams.limit() + ADDITIONAL_QUERY_DATA_COUNT;
if (reviewStatus == ReviewStatus.NOT_STARTED) {
return runnerPostPageRepository.pageBySupporterIdAndReviewStatusNotStarted(pageParams.cursor(), queryCount, supporterId);
return runnerPostPageRepository.pageBySupporterIdAndReviewStatusNotStarted(pageParams.cursor(), pageParams.getLimitForQuery(), supporterId);
}
return runnerPostPageRepository.pageBySupporterIdAndReviewStatus(pageParams.cursor(), queryCount, supporterId, reviewStatus);
return runnerPostPageRepository.pageBySupporterIdAndReviewStatus(pageParams.cursor(), pageParams.getLimitForQuery(), supporterId, reviewStatus);
}

private RunnerPostsApplicantCount readRunnerPostsApplicantCount(final List<RunnerPost> runnerPosts) {
Expand All @@ -90,8 +86,7 @@ public PageResponse<RunnerPostResponse.SimpleByRunner> pageRunnerPostByRunnerIdA
final Long runnerId,
final ReviewStatus reviewStatus
) {
final int queryCount = pageParams.limit() + ADDITIONAL_QUERY_DATA_COUNT;
final List<RunnerPost> runnerPosts = runnerPostPageRepository.pageByRunnerIdAndReviewStatus(pageParams.cursor(), queryCount, runnerId, reviewStatus);
final List<RunnerPost> runnerPosts = runnerPostPageRepository.pageByRunnerIdAndReviewStatus(pageParams.cursor(), pageParams.getLimitForQuery(), runnerId, reviewStatus);
final List<RunnerPostTag> runnerPostTags = runnerPostPageRepository.findRunnerPostTagsByRunnerPosts(runnerPosts);
final RunnerPostsApplicantCount runnerPostsApplicantCount = readRunnerPostsApplicantCount(runnerPosts);
final List<RunnerPostResponse.SimpleByRunner> responses = runnerPosts.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,10 @@
import static touch.baton.domain.common.exception.ClientErrorCode.INVALID_QUERY_STRING_FORMAT;

public record PageParams(Long cursor, @ValidNotNull(clientErrorCode = INVALID_QUERY_STRING_FORMAT) Integer limit) {

private static final int ADDITIONAL_QUERY_DATA_COUNT = 1;

public Integer getLimitForQuery() {
return limit + ADDITIONAL_QUERY_DATA_COUNT;
}
}

0 comments on commit ab0172f

Please sign in to comment.