-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Pull Notification Pagination 적용 (#113)
- Loading branch information
Showing
13 changed files
with
196 additions
and
18 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
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
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
11 changes: 11 additions & 0 deletions
11
...java/io/oeid/mogakgo/domain/notification/infrastructure/NotificationCustomRepository.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,11 @@ | ||
package io.oeid.mogakgo.domain.notification.infrastructure; | ||
|
||
|
||
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq; | ||
import io.oeid.mogakgo.common.base.CursorPaginationResult; | ||
import io.oeid.mogakgo.domain.notification.presentation.dto.res.NotificationPublicApiRes; | ||
|
||
public interface NotificationCustomRepository { | ||
|
||
CursorPaginationResult<NotificationPublicApiRes> findByUserIdWithPagination(Long userId, CursorPaginationInfoReq pageable); | ||
} |
60 changes: 60 additions & 0 deletions
60
.../io/oeid/mogakgo/domain/notification/infrastructure/NotificationCustomRepositoryImpl.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,60 @@ | ||
package io.oeid.mogakgo.domain.notification.infrastructure; | ||
|
||
|
||
import static io.oeid.mogakgo.domain.notification.domain.QNotification.notification; | ||
import static io.oeid.mogakgo.domain.user.domain.QUser.user; | ||
|
||
import com.querydsl.core.types.Projections; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import io.oeid.mogakgo.common.base.CursorPaginationInfoReq; | ||
import io.oeid.mogakgo.common.base.CursorPaginationResult; | ||
import io.oeid.mogakgo.domain.notification.presentation.dto.res.NotificationPublicApiRes; | ||
import io.oeid.mogakgo.domain.notification.presentation.vo.NotificationDataVo; | ||
import io.oeid.mogakgo.domain.notification.presentation.vo.NotificationSenderVo; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class NotificationCustomRepositoryImpl implements NotificationCustomRepository { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
public CursorPaginationResult<NotificationPublicApiRes> findByUserIdWithPagination(Long userId, | ||
CursorPaginationInfoReq pageable) { | ||
List<NotificationPublicApiRes> result = jpaQueryFactory.select( | ||
Projections.constructor( | ||
NotificationPublicApiRes.class, | ||
notification.id, | ||
notification.notificationTag, | ||
Projections.constructor( | ||
NotificationSenderVo.class, | ||
notification.sender.username, | ||
notification.sender.id, | ||
notification.sender.avatarUrl | ||
), | ||
Projections.constructor( | ||
NotificationDataVo.class, | ||
notification.detailData, | ||
notification.createdAt | ||
) | ||
) | ||
) | ||
.from(notification) | ||
.join(notification.sender, user) | ||
.where( | ||
cursorIdCondition(pageable.getCursorId()), | ||
notification.receiver.id.eq(userId)) | ||
.orderBy(notification.id.desc()) | ||
.limit(pageable.getPageSize() + 1L) | ||
.fetch(); | ||
return CursorPaginationResult.fromDataWithExtraItemForNextCheck(result, | ||
pageable.getPageSize()); | ||
} | ||
|
||
private BooleanExpression cursorIdCondition(Long cursorId) { | ||
return cursorId != null ? notification.id.lt(cursorId) : null; | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...va/io/oeid/mogakgo/domain/notification/presentation/dto/res/NotificationPublicApiRes.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,22 @@ | ||
package io.oeid.mogakgo.domain.notification.presentation.dto.res; | ||
|
||
import io.oeid.mogakgo.domain.notification.domain.enums.NotificationTag; | ||
import io.oeid.mogakgo.domain.notification.presentation.vo.NotificationDataVo; | ||
import io.oeid.mogakgo.domain.notification.presentation.vo.NotificationSenderVo; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Schema(description = "알림 API 응답") | ||
@Getter | ||
@AllArgsConstructor | ||
public class NotificationPublicApiRes { | ||
|
||
@Schema(description = "알림 ID") | ||
private Long id; | ||
@Schema(description = "알림 형식") | ||
private NotificationTag tag; | ||
private NotificationSenderVo sender; | ||
private NotificationDataVo data; | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
src/main/java/io/oeid/mogakgo/domain/notification/presentation/vo/NotificationDataVo.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,16 @@ | ||
package io.oeid.mogakgo.domain.notification.presentation.vo; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import java.time.LocalDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Schema(description = "알림 데이터") | ||
@Getter | ||
@AllArgsConstructor | ||
public class NotificationDataVo { | ||
|
||
private final String detail; | ||
private final LocalDateTime createdAt; | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/io/oeid/mogakgo/domain/notification/presentation/vo/NotificationSenderVo.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,19 @@ | ||
package io.oeid.mogakgo.domain.notification.presentation.vo; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Schema(description = "알림 발신자 정보") | ||
@Getter | ||
@AllArgsConstructor(access = AccessLevel.PUBLIC) | ||
public class NotificationSenderVo { | ||
@Schema(description = "알림 전송자 이름", defaultValue = "mogakgo") | ||
private String name; | ||
@Schema(description = "알림 전송자 아이디", nullable = true) | ||
private Long id; | ||
@Schema(description = "알림 전송자 프로필 이미지 URL", nullable = true) | ||
private String profileImageUrl; | ||
|
||
} |