Skip to content

Commit

Permalink
fix : 공연 상세 조회 리스트 쿼리 수정 (#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 10, 2024
1 parent 862cf19 commit bac8baa
Show file tree
Hide file tree
Showing 31 changed files with 588 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.example.artist.service.dto.request.ArtistUpdateServiceRequest;
import com.example.artist.service.dto.response.ArtistDetailServiceResponse;
import com.example.artist.service.dto.response.ArtistKoreanNameServiceResponse;
import com.example.artist.service.dto.response.ArtistKoreanNameWithShowIdServiceResponse;
import com.example.component.FileUploadComponent;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -43,6 +44,12 @@ public List<ArtistKoreanNameServiceResponse> findAllArtistKoreanName() {
.toList();
}

public List<ArtistKoreanNameWithShowIdServiceResponse> findArtistKoreanNamesWithShowId() {
return artistUseCase.findArtistKoreanNamesWithShowId().stream()
.map(ArtistKoreanNameWithShowIdServiceResponse::from)
.toList();
}

public ArtistDetailServiceResponse findArtistById(UUID id) {
ArtistDetailDomainResponse response;
try {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.artist.service.dto.response;

import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.dto.artist.response.ArtistKoreanNamesWithShowIdDomainResponse;

@Builder
public record ArtistKoreanNameWithShowIdServiceResponse(
UUID showId,
List<ArtistKoreanNameServiceResponse> koreanNameServiceResponses
) {

public static ArtistKoreanNameWithShowIdServiceResponse from(
ArtistKoreanNamesWithShowIdDomainResponse domainResponse
) {
var koreanNames = domainResponse.koreanNameDomainResponses()
.stream()
.map(ArtistKoreanNameServiceResponse::new)
.toList();

return ArtistKoreanNameWithShowIdServiceResponse.builder()
.showId(domainResponse.showId())
.koreanNameServiceResponses(koreanNames)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.genre.service.dto.request.GenreCreateServiceRequest;
import com.example.genre.service.dto.request.GenreUpdateServiceRequest;
import com.example.genre.service.dto.response.GenreNameServiceResponse;
import com.example.genre.service.dto.response.GenreNameWithShowIdServiceResponse;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.UUID;
Expand All @@ -23,6 +24,11 @@ public void save(GenreCreateServiceRequest genreCreateServiceRequest) {
genreUseCase.save(genreCreateServiceRequest.toGenre());
}

public List<GenreNameWithShowIdServiceResponse> findGenreNamesWithShowId() {
return genreUseCase.findGenreNamesWithShowId().stream()
.map(GenreNameWithShowIdServiceResponse::new)
.toList();
}

public List<GenreNameServiceResponse> findAllGenres() {
List<Genre> genres = genreUseCase.findAllGenres();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.genre.service.dto.response;

import java.util.List;
import java.util.UUID;
import org.example.dto.genre.response.GenreNamesWithShowIdDomainResponse;

public record GenreNameWithShowIdServiceResponse(
UUID showId,
List<GenreNameServiceResponse> genreNames
) {

public GenreNameWithShowIdServiceResponse(
GenreNamesWithShowIdDomainResponse response
) {
this(
response.showId(),
response.genreNames().stream()
.map(GenreNameServiceResponse::new)
.toList()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ public String createShow(@Valid ShowCreateApiForm showCreateApiForm) {

@GetMapping("/list")
public String findAllShow(Model model) {
List<ShowInfoApiResponse> shows = showAdminService.findAllShowInfos()
.stream()
var showWithTicketingTimes = showAdminService.findShowDetailWithTicketingTimes();

List<ShowInfoApiResponse> shows = showWithTicketingTimes.stream()
.map(ShowInfoApiResponse::new)
.toList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ public ShowInfoApiResponse(ShowInfoServiceResponse showInfoServiceResponse) {
);
}

public static List<ShowInfoApiResponse> from(
List<ShowInfoServiceResponse> showInfoServiceResponses
) {
return showInfoServiceResponses.stream()
.map(ShowInfoApiResponse::new)
.toList();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.show.controller.dto.response;

import com.example.show.service.dto.response.ShowSeatServiceResponse;
import com.example.show.service.dto.response.ShowTicketingSiteServiceResponse;
import com.example.show.service.dto.response.ShowTicketingTimeServiceResponse;
import java.time.LocalDate;
import java.util.List;
import java.util.UUID;
import org.example.dto.show.response.ShowTicketingTimeDomainResponse;
import org.example.dto.show.response.ShowWithTicketingTimesDomainResponse;

public record ShowWithTicketingTimesServiceResponse(
UUID id,
String title,
String content,
LocalDate startDate,
LocalDate endDate,
String location,
String image,
ShowSeatServiceResponse seats,
ShowTicketingSiteServiceResponse ticketingSiteInfos,
List<ShowTicketingTimeServiceResponse> ticketingTimes
) {

public ShowWithTicketingTimesServiceResponse(
ShowWithTicketingTimesDomainResponse domainResponse
) {
this(
domainResponse.show().id(),
domainResponse.show().title(),
domainResponse.show().content(),
domainResponse.show().startDate(),
domainResponse.show().endDate(),
domainResponse.show().location(),
domainResponse.show().image(),
ShowSeatServiceResponse.from(domainResponse.show().seatPrices()),
ShowTicketingSiteServiceResponse.from(domainResponse.show().ticketingSites()),
toShowTicketingTimeServiceResponses(domainResponse.ticketingTimes())
);
}

private static List<ShowTicketingTimeServiceResponse> toShowTicketingTimeServiceResponses(
List<ShowTicketingTimeDomainResponse> ticketingSites
) {
return ticketingSites.stream()
.map(ShowTicketingTimeServiceResponse::from)
.toList();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import lombok.RequiredArgsConstructor;
import org.example.dto.show.response.ShowInfoDomainResponse;
import org.example.exception.BusinessException;
import org.example.usecase.artist.ArtistUseCase;
import org.example.usecase.genre.GenreUseCase;
import org.example.usecase.show.ShowUseCase;
import org.springframework.stereotype.Service;

Expand All @@ -22,6 +24,8 @@
public class ShowAdminService {

private final ShowUseCase showUseCase;
private final GenreUseCase genreUseCase;
private final ArtistUseCase artistUseCase;
private final FileUploadComponent fileUploadComponent;
private final MessagePublisher messagePublisher;

Expand All @@ -41,11 +45,17 @@ public void save(ShowCreateServiceRequest showCreateServiceRequest) {
);
}

public List<ShowInfoServiceResponse> findAllShowInfos() {
List<ShowInfoDomainResponse> showInfoDomainResponse = showUseCase.findAllShowInfos();
return showInfoDomainResponse.stream()
.map(ShowInfoServiceResponse::new)
.toList();
public List<ShowInfoServiceResponse> findShowDetailWithTicketingTimes() {
var showWithTicketingTimesDomainResponses = showUseCase.findShowDetailWithTicketingTimes();
var artistKoreanNameWithShowIdDomainResponses = artistUseCase.findArtistKoreanNamesWithShowId();
var genreNameWithShowIdDomainResponses = genreUseCase.findGenreNamesWithShowId();

return ShowInfoServiceResponse.as(
showWithTicketingTimesDomainResponses,
artistKoreanNameWithShowIdDomainResponses,
genreNameWithShowIdDomainResponses
);

}

public ShowInfoServiceResponse findShowInfo(UUID id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@
import java.util.UUID;
import lombok.Builder;
import org.example.dto.artist.response.ArtistKoreanNameDomainResponse;
import org.example.dto.artist.response.ArtistKoreanNamesWithShowIdDomainResponse;
import org.example.dto.genre.response.GenreNameDomainResponse;
import org.example.dto.genre.response.GenreNamesWithShowIdDomainResponse;
import org.example.dto.show.response.ShowInfoDomainResponse;
import org.example.dto.show.response.ShowTicketingTimeDomainResponse;
import org.example.dto.show.response.ShowWithTicketingTimesDomainResponse;

@Builder
public record ShowInfoServiceResponse(
Expand Down Expand Up @@ -45,6 +48,43 @@ public ShowInfoServiceResponse(ShowInfoDomainResponse showInfo) {
);
}

public static List<ShowInfoServiceResponse> as(
List<ShowWithTicketingTimesDomainResponse> showWithTicketingTimes,
List<ArtistKoreanNamesWithShowIdDomainResponse> artistNamesWithShowId,
List<GenreNamesWithShowIdDomainResponse> genreNamesWithShowId
) {
return showWithTicketingTimes.stream()
.map(showWithTicketingTime -> {
var artistKoreanNameResponses = getArtistKoreanNameResponses(
artistNamesWithShowId,
showWithTicketingTime
);
var genreNameResponses = getGenreNameResponses(
genreNamesWithShowId,
showWithTicketingTime
);

return new ShowInfoServiceResponse(
showWithTicketingTime.show().id(),
showWithTicketingTime.show().title(),
showWithTicketingTime.show().content(),
showWithTicketingTime.show().startDate(),
showWithTicketingTime.show().endDate(),
showWithTicketingTime.show().location(),
showWithTicketingTime.show().image(),
ShowSeatServiceResponse.from(showWithTicketingTime.show().seatPrices()),
ShowTicketingSiteServiceResponse.from(
showWithTicketingTime.show().ticketingSites()),
showWithTicketingTime.ticketingTimes().stream()
.map(ShowTicketingTimeServiceResponse::from)
.toList(),
artistKoreanNameResponses,
genreNameResponses
);
})
.toList();
}

private static List<ShowTicketingTimeServiceResponse> toShowTicketingTimeServiceResponses(
Set<ShowTicketingTimeDomainResponse> ticketingSites
) {
Expand All @@ -68,4 +108,28 @@ private static List<GenreNameServiceResponse> toGenreNameServiceResponses(
.map(GenreNameServiceResponse::new)
.toList();
}

private static List<ArtistKoreanNameServiceResponse> getArtistKoreanNameResponses(
List<ArtistKoreanNamesWithShowIdDomainResponse> artistNamesWithShowId,
ShowWithTicketingTimesDomainResponse showWitTicketingTimes
) {
return artistNamesWithShowId.stream()
.filter(
artistResponse -> artistResponse.showId().equals(showWitTicketingTimes.show().id()))
.flatMap(artistResponse -> artistResponse.koreanNameDomainResponses().stream())
.map(ArtistKoreanNameServiceResponse::new)
.toList();
}

private static List<GenreNameServiceResponse> getGenreNameResponses(
List<GenreNamesWithShowIdDomainResponse> genreNamesWithShowId,
ShowWithTicketingTimesDomainResponse showWithTicketingTimes
) {
return genreNamesWithShowId.stream()
.filter(
genreResponse -> genreResponse.showId().equals(showWithTicketingTimes.show().id()))
.flatMap(genreResponse -> genreResponse.genreNames().stream())
.map(GenreNameServiceResponse::new)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.example.dto.show.request.ShowUpdateDomainRequest;
import org.example.fixture.domain.ShowArtistFixture;
import org.example.fixture.domain.ShowGenreFixture;
import org.example.usecase.artist.ArtistUseCase;
import org.example.usecase.genre.GenreUseCase;
import org.example.usecase.show.ShowUseCase;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -28,11 +30,15 @@
class ShowAdminServiceTest {

private final ShowUseCase showUseCase = mock(ShowUseCase.class);
private final GenreUseCase genreUseCase = mock(GenreUseCase.class);
private final ArtistUseCase artistUseCase = mock(ArtistUseCase.class);
private final FileUploadComponent fileUploadComponent = mock(FileUploadComponent.class);
private final MessagePublisher messagePublisher = mock(MessagePublisher.class);

private final ShowAdminService showAdminService = new ShowAdminService(
showUseCase,
genreUseCase,
artistUseCase,
fileUploadComponent,
messagePublisher
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.example.dto.artist.response;

import java.util.List;
import java.util.UUID;

public record ArtistKoreanNamesWithShowIdDomainResponse(
UUID showId,
List<ArtistKoreanNameDomainResponse> koreanNameDomainResponses
) {

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

import java.util.List;
import java.util.UUID;

public record GenreNamesWithShowIdDomainResponse(
UUID showId,
List<GenreNameDomainResponse> genreNames
) {

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

import java.util.List;

public record ShowWithTicketingTimesDomainResponse(
ShowDomainResponse show,
List<ShowTicketingTimeDomainResponse> ticketingTimes
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
import java.util.UUID;
import org.example.dto.show.response.ShowDetailDomainResponse;
import org.example.dto.show.response.ShowInfoDomainResponse;
import org.example.dto.show.response.ShowWithTicketingTimesDomainResponse;

public interface ShowQuerydslRepository {

Optional<ShowDetailDomainResponse> findShowDetailById(UUID id);

List<ShowInfoDomainResponse> findAllShowInfos();
List<ShowWithTicketingTimesDomainResponse> findShowDetailWithTicketingTimes();

Optional<ShowInfoDomainResponse> findShowInfoById(UUID id);
}
Loading

0 comments on commit bac8baa

Please sign in to comment.