diff --git a/app/api/common-api/src/main/java/org/example/util/ValidatorUser.java b/app/api/common-api/src/main/java/org/example/util/ValidatorUser.java new file mode 100644 index 00000000..4e8c1a16 --- /dev/null +++ b/app/api/common-api/src/main/java/org/example/util/ValidatorUser.java @@ -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(); + } + +} diff --git a/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java b/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java index 63e9b539..67b04279 100644 --- a/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java +++ b/app/api/show-api/src/main/java/com/example/show/controller/ShowController.java @@ -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; @@ -112,11 +113,14 @@ public ResponseEntity> @GetMapping("/{showId}") @Operation(summary = "공연 상세 조회") public ResponseEntity 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)) ); } diff --git a/app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowDetailApiResponse.java b/app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowDetailApiResponse.java index 559896e0..a4db43e3 100644 --- a/app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowDetailApiResponse.java +++ b/app/api/show-api/src/main/java/com/example/show/controller/dto/response/ShowDetailApiResponse.java @@ -28,6 +28,9 @@ public record ShowDetailApiResponse( @Schema(description = "공연 포스터 주소") String posterImageURL, + @Schema(description = "공연 포스터 주소") + boolean isInterested, + @Schema(description = "아티스트 정보") List artists, @@ -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) diff --git a/app/api/show-api/src/main/java/com/example/show/service/ShowService.java b/app/api/show-api/src/main/java/com/example/show/service/ShowService.java index e4d64df1..3c8a9870 100644 --- a/app/api/show-api/src/main/java/com/example/show/service/ShowService.java +++ b/app/api/show-api/src/main/java/com/example/show/service/ShowService.java @@ -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 searchShow( @@ -161,7 +163,8 @@ public void alertReservation( public PaginationServiceResponse findAlertShows( ShowAlertPaginationServiceRequest request ) { - List ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId(request.userId()); + List ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId( + request.userId()); List showIdsToAlert = ticketingAlerts.stream() .map(TicketingAlert::getShowId) .distinct() @@ -178,7 +181,8 @@ public PaginationServiceResponse findAlertShows } public TerminatedTicketingShowCountServiceResponse countTerminatedTicketingShow(UUID userId) { - List ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId(userId); + List ticketingAlerts = ticketingAlertUseCase.findTicketingAlertsByUserId( + userId); List showIdsToAlert = ticketingAlerts.stream() .map(TicketingAlert::getShowId) .distinct() diff --git a/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowDetailServiceResponse.java b/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowDetailServiceResponse.java index cf2b9274..835af703 100644 --- a/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowDetailServiceResponse.java +++ b/app/api/show-api/src/main/java/com/example/show/service/dto/response/ShowDetailServiceResponse.java @@ -16,6 +16,7 @@ public record ShowDetailServiceResponse( LocalDate endDate, String location, String posterImageURL, + boolean isInterested, List artists, List genres, List ticketingTimes, @@ -23,7 +24,10 @@ public record ShowDetailServiceResponse( 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()) @@ -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) diff --git a/app/api/show-api/src/test/java/show/service/ShowServiceTest.java b/app/api/show-api/src/test/java/show/service/ShowServiceTest.java index e56e0c7f..78fd4631 100644 --- a/app/api/show-api/src/test/java/show/service/ShowServiceTest.java +++ b/app/api/show-api/src/test/java/show/service/ShowServiceTest.java @@ -38,6 +38,7 @@ class ShowServiceTest { @DisplayName("공연 상세 조회할 때 조회수를 올리고 데이터를 반환한다.") void showDetailWithUpViewCount() { //given + UUID userId = UUID.randomUUID(); UUID showId = UUID.randomUUID(); String viewIdentifier = "testIdentifier"; given( @@ -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); @@ -62,6 +63,7 @@ void showDetailWithUpViewCount() { @DisplayName("공연 상세 조회할 때 조회수를 올리지 않고 데이터를 반환한다.") void showDetailNoneUpViewCount() { //given + UUID userId = UUID.randomUUID(); UUID showId = UUID.randomUUID(); String viewIdentifier = "testIdentifier"; given( @@ -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); diff --git a/app/domain/user-domain/src/main/java/org/example/usecase/UserShowUseCase.java b/app/domain/user-domain/src/main/java/org/example/usecase/UserShowUseCase.java index d3e50229..f68921ce 100644 --- a/app/domain/user-domain/src/main/java/org/example/usecase/UserShowUseCase.java +++ b/app/domain/user-domain/src/main/java/org/example/usecase/UserShowUseCase.java @@ -26,10 +26,7 @@ public class UserShowUseCase { @Transactional public InterestShow interest(InterestShowDomainRequest request) { - Optional optInterestShow = interestShowRepository.findByShowIdAndUserId( - request.showId(), - request.userId() - ); + Optional optInterestShow = findByShowIdAndUserId(request.showId(), request.userId()); if (optInterestShow.isEmpty()) { return interestShowRepository.save( @@ -46,6 +43,10 @@ public InterestShow interest(InterestShowDomainRequest request) { return interestShow; } + public Optional findByShowIdAndUserId(UUID showId, UUID userId) { + return interestShowRepository.findByShowIdAndUserId(showId, userId); + } + public List findArtistSubscriptionByUserId(UUID userId) { return artistSubscriptionRepository.findAllByUserIdAndIsDeletedFalse(userId); }