From fb1f9afc9c36a9fcb9f576fcfcf4d734708e51c1 Mon Sep 17 00:00:00 2001 From: GaBaljaintheroom Date: Wed, 28 Aug 2024 13:51:32 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EA=B3=B5=EC=97=B0=20=EB=AA=A9=EB=A1=9D?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20=EC=BF=BC=EB=A6=AC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/example/show/service/ShowService.java | 7 +++---- .../dto/request/ShowPaginationServiceRequest.java | 4 +++- .../dto/response/ShowPaginationServiceResponse.java | 13 +------------ .../repository/show/ShowQuerydslRepositoryImpl.java | 7 +++++++ 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/api/show-api/src/main/java/com/example/show/service/ShowService.java b/app/api/show-api/src/main/java/com/example/show/service/ShowService.java index 1f122c5f..e4d64df1 100644 --- a/app/api/show-api/src/main/java/com/example/show/service/ShowService.java +++ b/app/api/show-api/src/main/java/com/example/show/service/ShowService.java @@ -23,7 +23,6 @@ import java.time.LocalDateTime; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; @@ -75,13 +74,13 @@ public PaginationServiceResponse searchShow( public PaginationServiceResponse findShows( ShowPaginationServiceRequest request ) { - var response = showUseCase.findShows(request.toDomainRequest()); + LocalDateTime now = LocalDateTime.now(); + var response = showUseCase.findShows(request.toDomainRequest(now)); var data = response.data().stream() .map(domainResponse -> - ShowPaginationServiceResponse.of(domainResponse, request.onlyOpenSchedule()) + ShowPaginationServiceResponse.of(domainResponse, now) ) - .filter(Objects::nonNull) .toList(); return PaginationServiceResponse.of( diff --git a/app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowPaginationServiceRequest.java b/app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowPaginationServiceRequest.java index 4169cb4f..6bfdad76 100644 --- a/app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowPaginationServiceRequest.java +++ b/app/api/show-api/src/main/java/com/example/show/service/dto/request/ShowPaginationServiceRequest.java @@ -1,6 +1,7 @@ package com.example.show.service.dto.request; import com.example.show.controller.vo.ShowSortApiType; +import java.time.LocalDateTime; import java.util.UUID; import lombok.Builder; import org.example.dto.show.request.ShowPaginationDomainRequest; @@ -13,12 +14,13 @@ public record ShowPaginationServiceRequest( int size ) { - public ShowPaginationDomainRequest toDomainRequest() { + public ShowPaginationDomainRequest toDomainRequest(LocalDateTime now) { return ShowPaginationDomainRequest.builder() .sort(sort.toDomainType()) .onlyOpenSchedule(onlyOpenSchedule) .cursorId(cursorId) .size(size) + .now(now) .build(); } } diff --git a/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowPaginationServiceResponse.java b/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowPaginationServiceResponse.java index b6b7b6b5..9f4d544f 100644 --- a/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowPaginationServiceResponse.java +++ b/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowPaginationServiceResponse.java @@ -1,6 +1,5 @@ package com.example.show.service.dto.response; -import java.time.LocalDate; import java.time.LocalDateTime; import java.util.UUID; import lombok.Builder; @@ -17,18 +16,8 @@ public record ShowPaginationServiceResponse( ) { public static ShowPaginationServiceResponse of( ShowTicketingDomainResponse response, - boolean onlyOpenSchedule + LocalDateTime now ) { - LocalDateTime now = LocalDateTime.now(); - - if (onlyOpenSchedule && response.ticketingAt().isBefore(now)) { - return null; - } - - if (!onlyOpenSchedule && response.endDate().isBefore(LocalDate.now())) { - return null; - } - return ShowPaginationServiceResponse.builder() .id(response.id()) .title(response.title()) diff --git a/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java b/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java index abb1b2b7..9b0e299d 100644 --- a/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java +++ b/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java @@ -18,6 +18,7 @@ import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQuery; import com.querydsl.jpa.impl.JPAQueryFactory; +import java.time.LocalDate; import java.time.LocalDateTime; import java.util.List; import java.util.Optional; @@ -152,6 +153,12 @@ public long findTerminatedTicketingShowsCount(List showIds, LocalDateTime private Predicate getShowAlertsInCursorPagination(ShowPaginationDomainRequest request) { BooleanExpression wherePredicate = getDefaultPredicateExpression(); + if (request.onlyOpenSchedule()) { + return wherePredicate.and(showTicketingTime.ticketingAt.after(request.now())); + } else { + wherePredicate.and(show.endDate.after(LocalDate.now())); + } + if (request.cursorId() == null) { return wherePredicate; }