Skip to content

Commit

Permalink
fix: 공연 목록 조회 쿼리 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom committed Aug 28, 2024
1 parent e390fd7 commit fb1f9af
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -75,13 +74,13 @@ public PaginationServiceResponse<ShowSearchPaginationServiceParam> searchShow(
public PaginationServiceResponse<ShowPaginationServiceResponse> 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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -152,6 +153,12 @@ public long findTerminatedTicketingShowsCount(List<UUID> 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;
}
Expand Down

0 comments on commit fb1f9af

Please sign in to comment.