Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 공연 목록 조회 쿼리 수정 #138

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading