Skip to content

Commit

Permalink
fix: 사용자 알림 목록 요청 값 수정 (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom committed Jan 4, 2025
1 parent 95cd848 commit d2cb869
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.example.controller;

import jakarta.validation.constraints.Max;
import java.time.LocalDateTime;
import java.util.Optional;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -28,13 +29,15 @@ public class ShowAlarmController {
public ResponseEntity<PaginationApiResponse<ShowAlarmPaginationApiParam>> getShowAlarms(
@RequestParam(value = "fcmToken") String fcmToken,
@RequestParam(value = "cursorId", required = false) UUID cursorId,
@RequestParam(value = "cursorValue", required = false) LocalDateTime cursorValue,
@RequestParam(value = "size") @Max(value = 30, message = "조회하는 데이터의 최대 개수는 30입니다.")
Integer size
) {
var response = showAlarmService.getShowAlarms(
ShowAlarmsServiceRequest.builder()
.fcmToken(fcmToken)
.cursorId(cursorId)
.cursorValue(cursorValue)
.size(size)
.build()
);
Expand All @@ -43,7 +46,7 @@ public ResponseEntity<PaginationApiResponse<ShowAlarmPaginationApiParam>> getSho
.toList();

CursorApiResponse cursor = Optional.ofNullable(CursorApiResponse.getLastElement(data))
.map(element -> CursorApiResponse.toCursorId(element.id()))
.map(element -> CursorApiResponse.toCursorResponse(element.id(), element.createAt()))
.orElse(CursorApiResponse.noneCursor());

return ResponseEntity.ok(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.service.dto.request;

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.Builder;
import org.example.dto.request.ShowAlarmsDomainRequest;
Expand All @@ -8,12 +9,14 @@
public record ShowAlarmsServiceRequest(
String fcmToken,
UUID cursorId,
LocalDateTime cursorValue,
Integer size
) {
public ShowAlarmsDomainRequest toDomainRequest() {
return ShowAlarmsDomainRequest.builder()
.fcmToken(fcmToken)
.cursorId(cursorId)
.cursorValue(cursorValue)
.size(size)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package org.example.dto.request;

import java.time.LocalDateTime;
import java.util.UUID;
import lombok.Builder;

@Builder
public record ShowAlarmsDomainRequest(
String fcmToken,
UUID cursorId,
LocalDateTime cursorValue,
Integer size
) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.querydsl.core.types.Projections;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.jpa.impl.JPAQueryFactory;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -38,7 +39,12 @@ public ShowAlarmPaginationDomainResponse findAllWithCursorPagination(
)
)
.from(showAlarm)
.where(getDefaultPredicateInCursorPagination(request.cursorId()))
.where(getDefaultPredicateInCursorPagination(request.cursorId(), request.cursorValue()))
.orderBy(
showAlarm.createdAt.desc(),
showAlarm.id.asc()
)
.limit(request.size() + 1)
.fetch();

Slice<ShowAlarmDomainResponse> responseSlice = SliceUtil.makeSlice(
Expand All @@ -52,9 +58,19 @@ public ShowAlarmPaginationDomainResponse findAllWithCursorPagination(
.build();
}

private Predicate getDefaultPredicateInCursorPagination(UUID cursor) {
BooleanExpression defaultPredicate = showAlarm.isDeleted.isFalse();
private Predicate getDefaultPredicateInCursorPagination(
UUID cursorId,
LocalDateTime cursorValue
) {
BooleanExpression wherePredicate = showAlarm.isDeleted.isFalse();
if (cursorId != null && cursorValue != null) {
wherePredicate = wherePredicate.and(
showAlarm.createdAt.lt(cursorValue)
.or(showAlarm.createdAt.eq(cursorValue).and(showAlarm.id.gt(cursorId)))

);
}

return cursor == null ? defaultPredicate : showAlarm.id.gt(cursor).and(defaultPredicate);
return wherePredicate;
}
}

0 comments on commit d2cb869

Please sign in to comment.