Skip to content

Commit

Permalink
refactor: 공연 관심 설정 응답 필드 추가 (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 28, 2024
1 parent 9addc2e commit cf5932c
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.example.util;

import java.util.UUID;
import org.example.security.dto.AuthenticatedUser;

public final class ValidatorUser {

public static UUID getUserId(AuthenticatedUser user) {
if (user == null) {
return null;
}

return user.userId();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.example.dto.response.PaginationApiResponse;
import org.example.dto.response.PaginationServiceResponse;
import org.example.security.dto.AuthenticatedUser;
import org.example.util.ValidatorUser;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
Expand Down Expand Up @@ -112,11 +113,14 @@ public ResponseEntity<PaginationApiResponse<InterestShowPaginationApiResponse>>
@GetMapping("/{showId}")
@Operation(summary = "공연 상세 조회")
public ResponseEntity<ShowDetailApiResponse> getShow(
@AuthenticationPrincipal AuthenticatedUser user,
@PathVariable("showId") UUID showId,
@RequestHeader(value = "viewIdentifier") String viewIdentifier
) {
UUID userId = ValidatorUser.getUserId(user);

return ResponseEntity.ok(
ShowDetailApiResponse.from(showService.getShow(showId, viewIdentifier))
ShowDetailApiResponse.from(showService.getShow(userId, showId, viewIdentifier))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public record ShowDetailApiResponse(
@Schema(description = "공연 포스터 주소")
String posterImageURL,

@Schema(description = "공연 포스터 주소")
boolean isInterested,

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

Expand All @@ -52,6 +55,7 @@ public static ShowDetailApiResponse from(ShowDetailServiceResponse show) {
.endDate(DateTimeUtil.formatDate(show.endDate()))
.location(show.location())
.posterImageURL(show.posterImageURL())
.isInterested(show.isInterested())
.artists(
show.artists().stream()
.map(ShowArtistApiResponse::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,17 @@ public class ShowService {
private final MessagePublisher messagePublisher;
private final ViewCountComponent viewCountComponent;

public ShowDetailServiceResponse getShow(UUID id, String viewIdentifier) {
ShowDetailDomainResponse showDetail = showUseCase.findShowDetail(id);
public ShowDetailServiceResponse getShow(UUID userId, UUID showId, String viewIdentifier) {
ShowDetailDomainResponse showDetail = showUseCase.findShowDetail(showId);

boolean upViewCount = viewCountComponent.validateViewCount(id, viewIdentifier);
if (upViewCount) {
showUseCase.view(id);
boolean isInterested =
userId != null && userShowUseCase.findByShowIdAndUserId(showId, userId).isPresent();

if (viewCountComponent.validateViewCount(showId, viewIdentifier)) {
showUseCase.view(showId);
}

return ShowDetailServiceResponse.from(showDetail);
return ShowDetailServiceResponse.from(showDetail, isInterested);
}

public PaginationServiceResponse<ShowSearchPaginationServiceParam> searchShow(
Expand Down Expand Up @@ -161,7 +163,8 @@ public void alertReservation(
public PaginationServiceResponse<ShowAlertPaginationServiceParam> findAlertShows(
ShowAlertPaginationServiceRequest request
) {
List<TicketingAlert> ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId(request.userId());
List<TicketingAlert> ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId(
request.userId());
List<UUID> showIdsToAlert = ticketingAlerts.stream()
.map(TicketingAlert::getShowId)
.distinct()
Expand All @@ -178,7 +181,8 @@ public PaginationServiceResponse<ShowAlertPaginationServiceParam> findAlertShows
}

public TerminatedTicketingShowCountServiceResponse countTerminatedTicketingShow(UUID userId) {
List<TicketingAlert> ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId(userId);
List<TicketingAlert> ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId(
userId);
List<UUID> showIdsToAlert = ticketingAlerts.stream()
.map(TicketingAlert::getShowId)
.distinct()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ public record ShowDetailServiceResponse(
LocalDate endDate,
String location,
String posterImageURL,
boolean isInterested,
List<ShowArtistServiceResponse> artists,
List<ShowGenreServiceResponse> genres,
List<ShowTicketingTimeServiceResponse> ticketingTimes,
ShowSeatServiceResponse seats,
ShowTicketingSiteServiceResponse ticketingSites
) {

public static ShowDetailServiceResponse from(ShowDetailDomainResponse show) {
public static ShowDetailServiceResponse from(
ShowDetailDomainResponse show,
boolean isInterested
) {
return ShowDetailServiceResponse.builder()
.id(show.show().id())
.title(show.show().title())
Expand All @@ -32,6 +36,7 @@ public static ShowDetailServiceResponse from(ShowDetailDomainResponse show) {
.endDate(show.show().endDate())
.location(show.show().location())
.posterImageURL(show.show().image())
.isInterested(isInterested)
.artists(
show.artists().stream()
.map(ShowArtistServiceResponse::from)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class ShowServiceTest {
@DisplayName("공연 상세 조회할 때 조회수를 올리고 데이터를 반환한다.")
void showDetailWithUpViewCount() {
//given
UUID userId = UUID.randomUUID();
UUID showId = UUID.randomUUID();
String viewIdentifier = "testIdentifier";
given(
Expand All @@ -51,7 +52,7 @@ void showDetailWithUpViewCount() {
).willReturn(true);

//when
var result = showService.getShow(showId, viewIdentifier);
var result = showService.getShow(userId, showId, viewIdentifier);

//then
verify(showUseCase, times(1)).view(showId);
Expand All @@ -62,6 +63,7 @@ void showDetailWithUpViewCount() {
@DisplayName("공연 상세 조회할 때 조회수를 올리지 않고 데이터를 반환한다.")
void showDetailNoneUpViewCount() {
//given
UUID userId = UUID.randomUUID();
UUID showId = UUID.randomUUID();
String viewIdentifier = "testIdentifier";
given(
Expand All @@ -75,7 +77,7 @@ void showDetailNoneUpViewCount() {
).willReturn(false);

//when
var result = showService.getShow(showId, viewIdentifier);
var result = showService.getShow(userId, showId, viewIdentifier);

//then
verify(showUseCase, times(0)).view(showId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ public class UserShowUseCase {

@Transactional
public InterestShow interest(InterestShowDomainRequest request) {
Optional<InterestShow> optInterestShow = interestShowRepository.findByShowIdAndUserId(
request.showId(),
request.userId()
);
Optional<InterestShow> optInterestShow = findByShowIdAndUserId(request.showId(), request.userId());

if (optInterestShow.isEmpty()) {
return interestShowRepository.save(
Expand All @@ -46,6 +43,10 @@ public InterestShow interest(InterestShowDomainRequest request) {
return interestShow;
}

public Optional<InterestShow> findByShowIdAndUserId(UUID showId, UUID userId) {
return interestShowRepository.findByShowIdAndUserId(showId, userId);
}

public List<ArtistSubscription> findArtistSubscriptionByUserId(UUID userId) {
return artistSubscriptionRepository.findAllByUserIdAndIsDeletedFalse(userId);
}
Expand Down

0 comments on commit cf5932c

Please sign in to comment.