forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #119-헬퍼 매칭글 리스트 필터 및 페이지네이션 Repository 구현
- Loading branch information
1 parent
03e833f
commit 1c83124
Showing
1 changed file
with
75 additions
and
0 deletions.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
back/src/main/java/com/example/capstone/domain/help/repository/HelpRepositoryImpl.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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.capstone.domain.help.repository; | ||
|
||
import com.example.capstone.domain.help.dto.HelpListResponse; | ||
import com.example.capstone.domain.help.dto.HelpSliceResponse; | ||
import com.example.capstone.domain.help.entity.QHelp; | ||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Slice; | ||
import org.springframework.data.domain.SliceImpl; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
|
||
@RequiredArgsConstructor | ||
public class HelpRepositoryImpl implements HelpListRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
private QHelp help = QHelp.help; | ||
|
||
@Override | ||
public HelpSliceResponse getHelpListByPaging(Long cursorId, Pageable page, Boolean isDone, Boolean isHelper, UUID isMine) { | ||
List<HelpListResponse> helpList = jpaQueryFactory | ||
.select( | ||
Projections.constructor( | ||
HelpListResponse.class, | ||
help.id, help.title, | ||
help.author, help.country, | ||
help.createdDate, help.isDone, help.isHelper | ||
) | ||
) | ||
.from(help) | ||
.where(cursorId(cursorId), | ||
doneEq(isDone), | ||
helperEq(isHelper), | ||
mineEq(isMine)) | ||
.orderBy(help.createdDate.desc()) | ||
.limit(page.getPageSize() + 1) | ||
.fetch(); | ||
|
||
boolean hasNext = false; | ||
if(helpList.size() > page.getPageSize()) { | ||
helpList.remove(page.getPageSize()); | ||
hasNext = true; | ||
} | ||
|
||
Long lastCursorId = null; | ||
|
||
if(hasNext && helpList.size() != 0) { | ||
lastCursorId = helpList.get(helpList.size() - 1).id(); | ||
} | ||
|
||
return new HelpSliceResponse(lastCursorId, hasNext, helpList); | ||
} | ||
|
||
private BooleanExpression cursorId(Long cursorId) { | ||
return cursorId == null ? null : help.id.gt(cursorId); | ||
} | ||
|
||
private BooleanExpression doneEq(Boolean isDone) { | ||
return isDone == null ? null : help.isDone.eq(isDone); | ||
} | ||
|
||
private BooleanExpression helperEq(Boolean isHelper) { | ||
return isHelper == null ? null : help.isHelper.eq(isHelper); | ||
} | ||
|
||
private BooleanExpression mineEq(UUID isMine) { | ||
return isMine == null ? null : help.uuid.eq(isMine); | ||
} | ||
} |