Skip to content

Commit

Permalink
feat(CustomPageable): CustomPageable 구현 및 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
mikekks committed Nov 15, 2024
1 parent 1fdaed8 commit 76c272b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,10 @@ public class CustomPageable implements Pageable {
private final int size;
private final Sort sort;

public CustomPageable(int page, Sort sort) {
public CustomPageable(int page, int take, Sort sort) {
this.page = page;
this.sort = sort;
this.size = calculateSize(page);
}

private int calculateSize(int page) {
// 첫 번째 페이지는 11개, 그 이후부터는 12개
return page == 0 ? 11 : 12;
this.size = take;
}

@Override
Expand All @@ -32,8 +27,7 @@ public int getPageSize() {

@Override
public long getOffset() {
// 오프셋 계산
return page == 0 ? 0 : 11 + (page - 1) * 12;
return (long)(page - 1) * size + size;
}

@Override
Expand All @@ -43,27 +37,26 @@ public Sort getSort() {

@Override
public Pageable next() {
return new CustomPageable(this.page + 1, this.sort);
return new CustomPageable(this.page + 1, this.size, this.sort);
}

@Override
public Pageable previousOrFirst() {
return this.page == 0 ? this : new CustomPageable(this.page - 1, this.sort);
return this.page == 0 ? this : new CustomPageable(this.page + 1, this.size, this.sort);
}

@Override
public Pageable first() {
return new CustomPageable(0, this.sort);
return new CustomPageable(0, this.size, this.sort);
}

@Override
public boolean hasPrevious() {
return this.page > 0;
public Pageable withPage(int pageNumber) {
return new CustomPageable(pageNumber, this.size, this.sort);
}

@Override
public Pageable withPage(int pageNumber) {
// 새로운 페이지 번호로 CustomPageable 생성
return new CustomPageable(pageNumber, this.sort);
public boolean hasPrevious() {
return this.page > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public InternalMeetingGetAllMeetingDto getMeetings(
Sort sort = Sort.by(Sort.Direction.ASC, "id");

Page<Meeting> meetings = meetingRepository.findAllByQuery(queryCommand,
new CustomPageable(queryCommand.getPage() - 1, sort), time);
new CustomPageable(queryCommand.getPage() - 1, queryCommand.getTake(), sort), time);
Map<Long, Boolean> blockedUsers = memberBlockService.getBlockedUsers(orgIdRequestDto.orgId().longValue());

List<InternalMeetingResponseDto> meetingResponseDtos = meetings.getContent().stream()
Expand Down

0 comments on commit 76c272b

Please sign in to comment.