From 58302ce0e11a1426e80f5b114677b1de45a63181 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=AF=BC=EC=B0=AC=EA=B8=B0?= Date: Mon, 19 Aug 2024 21:25:30 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EA=B0=9C=EC=88=98=20=EC=A1=B0=ED=9A=8C?= =?UTF-8?q?=20API=20(#113)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org/example/config/SecurityConfig.java | 6 +- .../show/controller/ShowController.java | 2 +- .../controller/UserShowController.java | 75 +++++++++++++++++++ .../NumberOfInterestShowApiResponse.java | 12 +++ .../NumberOfSubscribedArtistApiResponse.java | 12 +++ .../NumberOfSubscribedGenreApiResponse.java | 12 +++ .../NumberOfTicketingAlertApiResponse.java | 12 +++ .../org/example/service/UserShowService.java | 42 +++++++++++ .../NumberOfInterestShowServiceResponse.java | 10 +++ ...mberOfSubscribedArtistServiceResponse.java | 10 +++ ...umberOfSubscribedGenreServiceResponse.java | 10 +++ ...NumberOfTicketingAlertServiceResponse.java | 10 +++ .../show/ShowQuerydslRepository.java | 4 + .../show/ShowQuerydslRepositoryImpl.java | 12 +++ .../org/example/usecase/show/ShowUseCase.java | 5 ++ .../InterestShowQuerydslRepository.java | 4 + .../InterestShowQuerydslRepositoryImpl.java | 21 +++++- .../interest/InterestShowRepository.java | 2 + .../ArtistSubscriptionRepository.java | 2 + .../GenreSubscriptionRepository.java | 2 + .../org/example/usecase/UserShowUseCase.java | 25 +++++++ 21 files changed, 285 insertions(+), 5 deletions(-) create mode 100644 app/api/user-api/src/main/java/org/example/controller/UserShowController.java create mode 100644 app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfInterestShowApiResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedArtistApiResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedGenreApiResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfTicketingAlertApiResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/service/UserShowService.java create mode 100644 app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfInterestShowServiceResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedArtistServiceResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedGenreServiceResponse.java create mode 100644 app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfTicketingAlertServiceResponse.java diff --git a/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java b/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java index 7b6ecfc7..65032a4a 100644 --- a/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java +++ b/app/api/common-api/src/main/java/org/example/config/SecurityConfig.java @@ -91,8 +91,12 @@ private RequestMatcher getMatcherForUserAndAdmin() { antMatcher(HttpMethod.POST, "/api/v1/users/logout"), antMatcher(HttpMethod.POST, "/api/v1/users/withdrawal"), antMatcher(HttpMethod.GET, "/api/v1/users/profile"), - antMatcher(HttpMethod.POST, "/api/v1/shows/**/interest"), + antMatcher(HttpMethod.GET, "/api/v1/users/shows/alerts/count"), + antMatcher(HttpMethod.GET, "/api/v1/users/artists/subscriptions/count"), + antMatcher(HttpMethod.GET, "/api/v1/users/genres/subscriptions/count"), antMatcher(HttpMethod.GET, "/api/v1/shows/interests"), + antMatcher(HttpMethod.GET, "/api/v1/users/shows/interests/count"), + antMatcher(HttpMethod.POST, "/api/v1/shows/**/interests"), antMatcher(HttpMethod.POST, "/api/v1/shows/{showId}/alert"), antMatcher(HttpMethod.GET, "/api/v1/shows/alerts"), antMatcher(HttpMethod.GET, "/api/v1/shows/{showId}/alert/reservations"), 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 d8acbdec..6a80ba2d 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 @@ -71,7 +71,7 @@ public ResponseEntity> getShows( } - @PostMapping("/{showId}/interest") + @PostMapping("/{showId}/interests") @Operation(summary = "공연 관심 등록 / 취소") public ResponseEntity interest( @PathVariable("showId") UUID showId, diff --git a/app/api/user-api/src/main/java/org/example/controller/UserShowController.java b/app/api/user-api/src/main/java/org/example/controller/UserShowController.java new file mode 100644 index 00000000..72a50a84 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/UserShowController.java @@ -0,0 +1,75 @@ +package org.example.controller; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.tags.Tag; +import java.time.LocalDateTime; +import lombok.RequiredArgsConstructor; +import org.example.controller.dto.response.NumberOfInterestShowApiResponse; +import org.example.controller.dto.response.NumberOfSubscribedArtistApiResponse; +import org.example.controller.dto.response.NumberOfSubscribedGenreApiResponse; +import org.example.controller.dto.response.NumberOfTicketingAlertApiResponse; +import org.example.security.dto.AuthenticatedUser; +import org.example.service.UserShowService; +import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/api/v1/users") +@Tag(name = "유저 공연") +public class UserShowController { + + private final UserShowService userShowService; + + @GetMapping("/shows/alerts/count") + @Operation(summary = "알림 설정한 공연 개수") + public ResponseEntity getNumberOfAlertShow( + @AuthenticationPrincipal AuthenticatedUser user + ) { + LocalDateTime now = LocalDateTime.now(); + return ResponseEntity.ok( + NumberOfTicketingAlertApiResponse.from( + userShowService.countAlertShows(user.userId(), now) + ) + ); + } + + @GetMapping("/artists/subscriptions/count") + @Operation(summary = "구독한 아티스트 수") + public ResponseEntity getNumberOfSubscribedArtist( + @AuthenticationPrincipal AuthenticatedUser user + ) { + return ResponseEntity.ok( + NumberOfSubscribedArtistApiResponse.from( + userShowService.countSubscribedArtists(user.userId()) + ) + ); + } + + @GetMapping("/genres/subscriptions/count") + @Operation(summary = "구독한 장르 수") + public ResponseEntity getNumberOfSubscribedGenre( + @AuthenticationPrincipal AuthenticatedUser user + ) { + return ResponseEntity.ok( + NumberOfSubscribedGenreApiResponse.from( + userShowService.countSubscribedGenres(user.userId()) + ) + ); + } + + @GetMapping("/shows/interests/count") + @Operation(summary = "관심 공연 개수") + public ResponseEntity getNumberOfInterestShow( + @AuthenticationPrincipal AuthenticatedUser user + ) { + return ResponseEntity.ok( + NumberOfInterestShowApiResponse.from( + userShowService.countInterestShows(user.userId()) + ) + ); + } +} diff --git a/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfInterestShowApiResponse.java b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfInterestShowApiResponse.java new file mode 100644 index 00000000..13256dea --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfInterestShowApiResponse.java @@ -0,0 +1,12 @@ +package org.example.controller.dto.response; + +import org.example.service.dto.response.NumberOfInterestShowServiceResponse; + +public record NumberOfInterestShowApiResponse( + long count +) { + + public static NumberOfInterestShowApiResponse from(NumberOfInterestShowServiceResponse response) { + return new NumberOfInterestShowApiResponse(response.count()); + } +} diff --git a/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedArtistApiResponse.java b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedArtistApiResponse.java new file mode 100644 index 00000000..7901df75 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedArtistApiResponse.java @@ -0,0 +1,12 @@ +package org.example.controller.dto.response; + +import org.example.service.dto.response.NumberOfSubscribedArtistServiceResponse; + +public record NumberOfSubscribedArtistApiResponse( + long count +) { + + public static NumberOfSubscribedArtistApiResponse from(NumberOfSubscribedArtistServiceResponse response) { + return new NumberOfSubscribedArtistApiResponse(response.count()); + } +} diff --git a/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedGenreApiResponse.java b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedGenreApiResponse.java new file mode 100644 index 00000000..9ac46b98 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfSubscribedGenreApiResponse.java @@ -0,0 +1,12 @@ +package org.example.controller.dto.response; + +import org.example.service.dto.response.NumberOfSubscribedGenreServiceResponse; + +public record NumberOfSubscribedGenreApiResponse( + long count +) { + + public static NumberOfSubscribedGenreApiResponse from(NumberOfSubscribedGenreServiceResponse response) { + return new NumberOfSubscribedGenreApiResponse(response.count()); + } +} diff --git a/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfTicketingAlertApiResponse.java b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfTicketingAlertApiResponse.java new file mode 100644 index 00000000..48dda393 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/controller/dto/response/NumberOfTicketingAlertApiResponse.java @@ -0,0 +1,12 @@ +package org.example.controller.dto.response; + +import org.example.service.dto.response.NumberOfTicketingAlertServiceResponse; + +public record NumberOfTicketingAlertApiResponse( + long count +) { + + public static NumberOfTicketingAlertApiResponse from(NumberOfTicketingAlertServiceResponse response) { + return new NumberOfTicketingAlertApiResponse(response.count()); + } +} diff --git a/app/api/user-api/src/main/java/org/example/service/UserShowService.java b/app/api/user-api/src/main/java/org/example/service/UserShowService.java new file mode 100644 index 00000000..e1ab40d0 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/service/UserShowService.java @@ -0,0 +1,42 @@ +package org.example.service; + +import java.time.LocalDateTime; +import java.util.UUID; +import lombok.RequiredArgsConstructor; +import org.example.service.dto.response.NumberOfInterestShowServiceResponse; +import org.example.service.dto.response.NumberOfSubscribedArtistServiceResponse; +import org.example.service.dto.response.NumberOfSubscribedGenreServiceResponse; +import org.example.service.dto.response.NumberOfTicketingAlertServiceResponse; +import org.example.usecase.UserShowUseCase; +import org.springframework.stereotype.Service; + +@Service +@RequiredArgsConstructor +public class UserShowService { + + private final UserShowUseCase userShowUseCase; + + public NumberOfTicketingAlertServiceResponse countAlertShows(UUID userId, LocalDateTime now) { + long numberOfTicketingAlert = userShowUseCase.countAlertShows(userId, now); + + return NumberOfTicketingAlertServiceResponse.from(numberOfTicketingAlert); + } + + public NumberOfSubscribedArtistServiceResponse countSubscribedArtists(UUID userId) { + return NumberOfSubscribedArtistServiceResponse.from( + userShowUseCase.countSubscribedArtists(userId) + ); + } + + public NumberOfSubscribedGenreServiceResponse countSubscribedGenres(UUID uuid) { + return NumberOfSubscribedGenreServiceResponse.from( + userShowUseCase.countSubscribedGenres(uuid) + ); + } + + public NumberOfInterestShowServiceResponse countInterestShows(UUID uuid) { + return NumberOfInterestShowServiceResponse.from( + userShowUseCase.countInterestShows(uuid) + ); + } +} diff --git a/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfInterestShowServiceResponse.java b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfInterestShowServiceResponse.java new file mode 100644 index 00000000..fbbd1c50 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfInterestShowServiceResponse.java @@ -0,0 +1,10 @@ +package org.example.service.dto.response; + +public record NumberOfInterestShowServiceResponse( + long count +) { + + public static NumberOfInterestShowServiceResponse from(long count) { + return new NumberOfInterestShowServiceResponse(count); + } +} diff --git a/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedArtistServiceResponse.java b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedArtistServiceResponse.java new file mode 100644 index 00000000..6b4d3872 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedArtistServiceResponse.java @@ -0,0 +1,10 @@ +package org.example.service.dto.response; + +public record NumberOfSubscribedArtistServiceResponse( + long count +) { + + public static NumberOfSubscribedArtistServiceResponse from(long count) { + return new NumberOfSubscribedArtistServiceResponse(count); + } +} diff --git a/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedGenreServiceResponse.java b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedGenreServiceResponse.java new file mode 100644 index 00000000..dac0cd56 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfSubscribedGenreServiceResponse.java @@ -0,0 +1,10 @@ +package org.example.service.dto.response; + +public record NumberOfSubscribedGenreServiceResponse( + long count +) { + + public static NumberOfSubscribedGenreServiceResponse from(long count) { + return new NumberOfSubscribedGenreServiceResponse(count); + } +} diff --git a/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfTicketingAlertServiceResponse.java b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfTicketingAlertServiceResponse.java new file mode 100644 index 00000000..5b33ad33 --- /dev/null +++ b/app/api/user-api/src/main/java/org/example/service/dto/response/NumberOfTicketingAlertServiceResponse.java @@ -0,0 +1,10 @@ +package org.example.service.dto.response; + +public record NumberOfTicketingAlertServiceResponse( + long count +) { + + public static NumberOfTicketingAlertServiceResponse from(long count) { + return new NumberOfTicketingAlertServiceResponse(count); + } +} diff --git a/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepository.java b/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepository.java index 39b3dbf9..77118447 100644 --- a/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepository.java +++ b/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepository.java @@ -1,5 +1,6 @@ package org.example.repository.show; +import java.time.LocalDateTime; import java.util.List; import java.util.Optional; import java.util.UUID; @@ -8,6 +9,7 @@ import org.example.dto.show.response.ShowInfoDomainResponse; import org.example.dto.show.response.ShowPaginationDomainResponse; import org.example.dto.show.response.ShowWithTicketingTimesDomainResponse; +import org.example.entity.show.Show; public interface ShowQuerydslRepository { @@ -18,4 +20,6 @@ public interface ShowQuerydslRepository { ShowPaginationDomainResponse findShows(ShowPaginationDomainRequest request); Optional findShowInfoById(UUID id); + + List findNotFinishedShowsIn(List showIds, LocalDateTime now); } diff --git a/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java b/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java index f0bfab22..908b727f 100644 --- a/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java +++ b/app/domain/show-domain/src/main/java/org/example/repository/show/ShowQuerydslRepositoryImpl.java @@ -121,6 +121,18 @@ public ShowPaginationDomainResponse findShows(ShowPaginationDomainRequest reques .build(); } + @Override + public List findNotFinishedShowsIn(List showIds, LocalDateTime now) { + return jpaQueryFactory + .selectFrom(show) + .where( + show.isDeleted.isFalse() + .and(show.id.in(showIds)) + .and(show.lastTicketingAt.after(now)) + ) + .fetch(); + } + private List findShowsByPopularity(ShowPaginationDomainRequest request) { BooleanExpression whereExpression = show.isDeleted.isFalse(); diff --git a/app/domain/show-domain/src/main/java/org/example/usecase/show/ShowUseCase.java b/app/domain/show-domain/src/main/java/org/example/usecase/show/ShowUseCase.java index 2f4e3b10..1faa99fb 100644 --- a/app/domain/show-domain/src/main/java/org/example/usecase/show/ShowUseCase.java +++ b/app/domain/show-domain/src/main/java/org/example/usecase/show/ShowUseCase.java @@ -1,5 +1,6 @@ package org.example.usecase.show; +import java.time.LocalDateTime; import java.util.List; import java.util.NoSuchElementException; import java.util.UUID; @@ -233,6 +234,10 @@ public ShowTicketingTime findTicketingTimeWithShow( .orElseThrow(NoSuchElementException::new); } + public List findNotFinishedTicketingShows(List showIds, LocalDateTime now) { + return showRepository.findNotFinishedShowsIn(showIds, now); + } + private Show findShowOrThrowNoSuchElementException(UUID id) { return showRepository.findById(id).orElseThrow(NoSuchElementException::new); } diff --git a/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepository.java b/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepository.java index 73cf637d..8e891acc 100644 --- a/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepository.java +++ b/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepository.java @@ -1,9 +1,13 @@ package org.example.repository.interest; +import java.time.LocalDateTime; +import java.util.UUID; import org.example.dto.request.InterestShowPaginationDomainRequest; import org.example.dto.response.InterestShowPaginationDomainResponse; public interface InterestShowQuerydslRepository { InterestShowPaginationDomainResponse findInterestShowList(InterestShowPaginationDomainRequest request); + + long countValidTicketingAlerts(UUID userId, LocalDateTime now); } diff --git a/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepositoryImpl.java b/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepositoryImpl.java index 465ed1ed..2c3c9010 100644 --- a/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepositoryImpl.java +++ b/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowQuerydslRepositoryImpl.java @@ -1,9 +1,12 @@ package org.example.repository.interest; import static org.example.entity.QInterestShow.interestShow; +import static org.example.entity.QTicketingAlert.ticketingAlert; import com.querydsl.core.types.dsl.BooleanExpression; import com.querydsl.jpa.impl.JPAQueryFactory; +import java.time.LocalDateTime; +import java.util.UUID; import lombok.RequiredArgsConstructor; import org.example.dto.request.InterestShowPaginationDomainRequest; import org.example.dto.response.InterestShowPaginationDomainResponse; @@ -39,9 +42,21 @@ public InterestShowPaginationDomainResponse findInterestShowList( .build(); } - private BooleanExpression getInterestShowPaginationConditions( - InterestShowPaginationDomainRequest request - ) { + @Override + public long countValidTicketingAlerts(UUID userId, LocalDateTime now) { + Long result = jpaQueryFactory.select(ticketingAlert.showId.countDistinct()) + .from(ticketingAlert) + .where( + ticketingAlert.isDeleted.isFalse() + .and(ticketingAlert.userId.eq(userId)) + .and(ticketingAlert.alertTime.gt(now)) + ) + .fetchOne(); + + return result == null ? 0 : result; + } + + private BooleanExpression getInterestShowPaginationConditions(InterestShowPaginationDomainRequest request) { BooleanExpression whereConditions = interestShow.userId.eq(request.userId()) .and(interestShow.isDeleted.isFalse()); diff --git a/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowRepository.java b/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowRepository.java index 1431f89a..3f15bf23 100644 --- a/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowRepository.java +++ b/app/domain/user-domain/src/main/java/org/example/repository/interest/InterestShowRepository.java @@ -8,4 +8,6 @@ public interface InterestShowRepository extends JpaRepository, InterestShowQuerydslRepository { Optional findByShowIdAndUserId(UUID showId, UUID userId); + + Long countInterestShowByUserIdAndIsDeletedFalse(UUID userId); } diff --git a/app/domain/user-domain/src/main/java/org/example/repository/subscription/artistsubscription/ArtistSubscriptionRepository.java b/app/domain/user-domain/src/main/java/org/example/repository/subscription/artistsubscription/ArtistSubscriptionRepository.java index 82d70767..0a589b63 100644 --- a/app/domain/user-domain/src/main/java/org/example/repository/subscription/artistsubscription/ArtistSubscriptionRepository.java +++ b/app/domain/user-domain/src/main/java/org/example/repository/subscription/artistsubscription/ArtistSubscriptionRepository.java @@ -9,4 +9,6 @@ public interface ArtistSubscriptionRepository extends JpaRepository, ArtistSubscriptionQuerydslRepository { List findAllByUserId(UUID userId); + + Long countByUserIdAndIsDeletedFalse(UUID userId); } diff --git a/app/domain/user-domain/src/main/java/org/example/repository/subscription/genresubscription/GenreSubscriptionRepository.java b/app/domain/user-domain/src/main/java/org/example/repository/subscription/genresubscription/GenreSubscriptionRepository.java index ff7fe22c..698176b1 100644 --- a/app/domain/user-domain/src/main/java/org/example/repository/subscription/genresubscription/GenreSubscriptionRepository.java +++ b/app/domain/user-domain/src/main/java/org/example/repository/subscription/genresubscription/GenreSubscriptionRepository.java @@ -11,4 +11,6 @@ public interface GenreSubscriptionRepository extends JpaRepository findAllByUserId(UUID userId); List findByUserIdAndIsDeletedFalse(UUID userId); + + Long countByUserIdAndIsDeletedFalse(UUID uuid); } 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 43af5036..cd7ec140 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 @@ -1,12 +1,16 @@ package org.example.usecase; +import java.time.LocalDateTime; import java.util.Optional; +import java.util.UUID; import lombok.RequiredArgsConstructor; import org.example.dto.request.InterestShowDomainRequest; import org.example.dto.request.InterestShowPaginationDomainRequest; import org.example.dto.response.InterestShowPaginationDomainResponse; import org.example.entity.InterestShow; import org.example.repository.interest.InterestShowRepository; +import org.example.repository.subscription.artistsubscription.ArtistSubscriptionRepository; +import org.example.repository.subscription.genresubscription.GenreSubscriptionRepository; import org.springframework.stereotype.Component; import org.springframework.transaction.annotation.Transactional; @@ -15,6 +19,8 @@ public class UserShowUseCase { private final InterestShowRepository interestShowRepository; + private final ArtistSubscriptionRepository artistSubscriptionRepository; + private final GenreSubscriptionRepository genreSubscriptionRepository; @Transactional public InterestShow interest(InterestShowDomainRequest request) { @@ -41,4 +47,23 @@ public InterestShow interest(InterestShowDomainRequest request) { public InterestShowPaginationDomainResponse findInterestShows(InterestShowPaginationDomainRequest request) { return interestShowRepository.findInterestShowList(request); } + + public long countAlertShows(UUID userId, LocalDateTime now) { + return interestShowRepository.countValidTicketingAlerts(userId, now); + } + + public long countSubscribedArtists(UUID userId) { + Long result = artistSubscriptionRepository.countByUserIdAndIsDeletedFalse(userId); + return result == null ? 0 : result; + } + + public long countSubscribedGenres(UUID userId) { + Long result = genreSubscriptionRepository.countByUserIdAndIsDeletedFalse(userId); + return result == null ? 0 : result; + } + + public long countInterestShows(UUID userId) { + Long result = interestShowRepository.countInterestShowByUserIdAndIsDeletedFalse(userId); + return result == null ? 0 : result; + } }