Skip to content

Commit

Permalink
fix: 공연 전체 목록 조회 기능 수정 (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 27, 2024
1 parent 5eb88e4 commit 7aff7b5
Show file tree
Hide file tree
Showing 12 changed files with 145 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -53,10 +52,8 @@ public class ShowController {
public ResponseEntity<PaginationApiResponse<ShowPaginationApiParam>> getShows(
@ParameterObject ShowPaginationApiRequest request
) {
LocalDateTime now = LocalDateTime.now();

PaginationServiceResponse<ShowPaginationServiceResponse> response = showService.findShows(
request.toServiceRequest(now)
request.toServiceRequest()
);

var data = response.data().stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.example.show.controller.vo.ShowSortApiType;
import com.example.show.service.dto.request.ShowPaginationServiceRequest;
import io.swagger.v3.oas.annotations.Parameter;
import java.time.LocalDateTime;
import java.util.UUID;
import org.springdoc.core.annotations.ParameterObject;

Expand All @@ -19,20 +18,16 @@ public record ShowPaginationApiRequest(
@Parameter(description = "이전 페이지네이션 마지막 데이터의 ID / 최초 조회라면 null")
UUID cursorId,

@Parameter(description = "이전 페이지네이션 마지막 데이터의 정렬 필드 값 (RECENT: reservationAt, POPULAR: viewCount) / 최초 조회라면 null")
UUID cursorValue,

@Parameter(required = true, description = "조회하려는 데이터 개수")
int size
) {

public ShowPaginationServiceRequest toServiceRequest(LocalDateTime now) {
public ShowPaginationServiceRequest toServiceRequest() {
return ShowPaginationServiceRequest.builder()
.sort(sort)
.onlyOpenSchedule(onlyOpenSchedule)
.cursorId(cursorId)
.cursorValue(cursorValue)
.size(size)
.now(now)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import com.example.show.service.dto.response.ShowPaginationServiceResponse;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.util.DateTimeUtil;

@Builder
public record ShowPaginationApiParam(
Expand All @@ -22,48 +22,20 @@ public record ShowPaginationApiParam(
String posterImageURL,

@Schema(description = "가장 근접한 예매 시간")
String reservationAt,
String ticketingAt,

@Schema(description = "오픈 예정인 티켓팅 일정이 있는지 여부")
boolean hasTicketingOpenSchedule,

@Schema(description = "조회수")
int viewCount,

@Schema(description = "아티스트 정보")
List<ShowArtistPaginationApiParam> artists,

@Schema(description = "장르 정보")
List<ShowGenrePaginationApiParam> genres,

@Schema(description = "예약 시간 정보")
List<ShowTicketingTimePaginationApiParam> showTicketingTimes
@Schema(description = "오픈 여부")
boolean isOpen
) {

public static ShowPaginationApiParam from(ShowPaginationServiceResponse response) {
return ShowPaginationApiParam.builder()
.id(response.id())
.title(response.title())
.location(response.location())
.posterImageURL(response.posterImageURL())
.reservationAt(response.reservationAt())
.hasTicketingOpenSchedule(response.hasTicketingOpenSchedule())
.viewCount(response.viewCount())
.artists(
response.artists().stream()
.map(ShowArtistPaginationApiParam::from)
.toList()
)
.genres(
response.genres().stream()
.map(ShowGenrePaginationApiParam::from)
.toList()
)
.showTicketingTimes(
response.showTicketingTimes().stream()
.map(ShowTicketingTimePaginationApiParam::from)
.toList()
)
.posterImageURL(response.image())
.ticketingAt(DateTimeUtil.formatDateTime(response.ticketingAt()))
.isOpen(response.isOpen())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
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,9 +76,12 @@ public PaginationServiceResponse<ShowPaginationServiceResponse> findShows(
ShowPaginationServiceRequest request
) {
var response = showUseCase.findShows(request.toDomainRequest());

var data = response.data().stream()
.map(
domainResponse -> ShowPaginationServiceResponse.from(domainResponse, request.now()))
.map(domainResponse ->
ShowPaginationServiceResponse.of(domainResponse, request.onlyOpenSchedule())
)
.filter(Objects::nonNull)
.toList();

return PaginationServiceResponse.of(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 @@ -11,19 +10,15 @@ public record ShowPaginationServiceRequest(
ShowSortApiType sort,
boolean onlyOpenSchedule,
UUID cursorId,
Object cursorValue,
int size,
LocalDateTime now
int size
) {

public ShowPaginationDomainRequest toDomainRequest() {
return ShowPaginationDomainRequest.builder()
.sort(sort.toDomainType())
.onlyOpenSchedule(onlyOpenSchedule)
.cursorId(cursorId)
.cursorValue(cursorValue)
.size(size)
.now(now)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,59 +1,41 @@
package com.example.show.service.dto.response;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import lombok.Builder;
import org.example.dto.show.response.ShowDetailDomainResponse;
import org.example.util.DateTimeUtil;
import org.example.dto.show.response.ShowTicketingDomainResponse;

@Builder
public record ShowPaginationServiceResponse(
UUID id,
String title,
LocalDateTime ticketingAt,
String location,
String posterImageURL,
String reservationAt,
boolean hasTicketingOpenSchedule,
int viewCount,
List<ShowArtistSimpleServiceResponse> artists,
List<ShowGenreSimpleServiceResponse> genres,
List<ShowTicketingTimeServiceParam> showTicketingTimes
String image,
boolean isOpen
) {
public static ShowPaginationServiceResponse of(
ShowTicketingDomainResponse response,
boolean onlyOpenSchedule
) {
LocalDateTime now = LocalDateTime.now();

public static ShowPaginationServiceResponse from(ShowDetailDomainResponse response, LocalDateTime now) {
List<ShowTicketingTimeServiceParam> ticketingTimes = response.showTicketingTimes().stream()
.map(ShowTicketingTimeServiceParam::from)
.toList();
if (onlyOpenSchedule && response.ticketingAt().isBefore(now)) {
return null;
}

Optional<ShowTicketingTimeServiceParam> optShowTicketingTime = ticketingTimes.stream()
.filter(ticketingTime -> now.isBefore(ticketingTime.ticketingAt()))
.findFirst();

String reservationAt = optShowTicketingTime.map(
showTicketingTime -> DateTimeUtil.formatDateTime(showTicketingTime.ticketingAt())
).orElseGet(() -> "");
if (!onlyOpenSchedule && response.endDate().isBefore(LocalDate.now())) {
return null;
}

return ShowPaginationServiceResponse.builder()
.id(response.show().id())
.title(response.show().title())
.location(response.show().location())
.posterImageURL(response.show().image())
.reservationAt(reservationAt)
.hasTicketingOpenSchedule(now.isBefore(response.show().lastTicketingAt()))
.viewCount(response.show().viewCount())
.artists(
response.artists().stream()
.map(ShowArtistSimpleServiceResponse::from)
.toList()
)
.genres(
response.genres().stream()
.map(ShowGenreSimpleServiceResponse::from)
.toList()
)
.showTicketingTimes(ticketingTimes)
.id(response.id())
.title(response.title())
.ticketingAt(response.ticketingAt())
.location(response.location())
.image(response.image())
.isOpen(response.ticketingAt().isBefore(now))
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public record ShowPaginationDomainRequest(
ShowSortType sort,
boolean onlyOpenSchedule,
UUID cursorId,
Object cursorValue,
int size,
LocalDateTime now
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.example.dto.show.response;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.UUID;

public record ShowTicketingDomainResponse(
UUID id,
String title,
LocalDate endDate,
LocalDateTime ticketingAt,
String location,
String image
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.dto.show.response;

import java.util.List;
import lombok.Builder;

@Builder
public record ShowTicketingPaginationDomainResponse(
List<ShowTicketingDomainResponse> data,
boolean hasNext
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.example.dto.show.request.ShowPaginationDomainRequest;
import org.example.dto.show.response.ShowDetailDomainResponse;
import org.example.dto.show.response.ShowInfoDomainResponse;
import org.example.dto.show.response.ShowPaginationDomainResponse;
import org.example.dto.show.response.ShowTicketingPaginationDomainResponse;
import org.example.dto.show.response.ShowWithTicketingTimesDomainResponse;

public interface ShowQuerydslRepository {
Expand All @@ -16,7 +16,7 @@ public interface ShowQuerydslRepository {

List<ShowWithTicketingTimesDomainResponse> findShowDetailWithTicketingTimes();

ShowPaginationDomainResponse findShows(ShowPaginationDomainRequest request);
ShowTicketingPaginationDomainResponse findShows(ShowPaginationDomainRequest request);

Optional<ShowInfoDomainResponse> findShowInfoById(UUID id);

Expand Down
Loading

0 comments on commit 7aff7b5

Please sign in to comment.