From 559ed4b19336610f01d7508ce1f99f7797ef9305 Mon Sep 17 00:00:00 2001 From: JunsuPark Date: Tue, 13 Aug 2024 02:53:29 +0900 Subject: [PATCH] fix : redis sub request (#102) --- .../example/artist/service/ArtistService.java | 39 +++++++++------ .../example/genre/service/GenreService.java | 41 +++++++++------ .../java/com/example/mq/MessagePublisher.java | 18 ------- .../ArtistSubscriptionServiceMessage.java | 18 ------- .../GenreSubscriptionServiceMessage.java | 19 ------- .../com/example/publish/MessagePublisher.java | 17 +++++++ .../ArtistSubscriptionServiceMessage.java | 22 ++++++++ .../GenreSubscriptionServiceMessage.java | 22 ++++++++ .../message/ReserveShowServiceMessage.java} | 5 +- ...wRelationArtistAndGenreServiceMessage.java | 2 +- .../TicketingReservationServiceMessage.java | 10 ++++ .../show/service/ShowAdminService.java | 4 +- .../artist/service/ArtistServiceTest.java | 13 +++-- .../java/genre/service/GenreServiceTest.java | 12 +++-- .../show/service/ShowAdminServiceTest.java | 4 +- .../user/UserQuerydslRepository.java | 2 + .../user/UserQuerydslRepositoryImpl.java | 10 ++++ .../java/org/example/usecase/UserUseCase.java | 4 ++ app/infrastructure/build.gradle | 2 +- .../build.gradle | 0 .../java/org/example/config/PubSubConfig.java | 0 .../ArtistSubscriptionInfraMessage.java | 11 ++-- .../GenreSubscriptionInfraMessage.java | 11 ++-- .../message/ReserveShowInfraMessage.java} | 14 ++---- ...howRelationArtistAndGenreInfraMessage.java | 2 +- .../TicketingReservationInfraMessage.java | 25 ++++++++++ .../publish/RedisMessagePublisher.java | 50 ++++++++----------- settings.gradle | 2 +- 28 files changed, 228 insertions(+), 151 deletions(-) delete mode 100644 app/api/show-api/src/main/java/com/example/mq/MessagePublisher.java delete mode 100644 app/api/show-api/src/main/java/com/example/mq/message/ArtistSubscriptionServiceMessage.java delete mode 100644 app/api/show-api/src/main/java/com/example/mq/message/GenreSubscriptionServiceMessage.java create mode 100644 app/api/show-api/src/main/java/com/example/publish/MessagePublisher.java create mode 100644 app/api/show-api/src/main/java/com/example/publish/message/ArtistSubscriptionServiceMessage.java create mode 100644 app/api/show-api/src/main/java/com/example/publish/message/GenreSubscriptionServiceMessage.java rename app/api/show-api/src/main/java/com/example/{mq/message/TicketingReservationServiceMessage.java => publish/message/ReserveShowServiceMessage.java} (68%) rename app/api/show-api/src/main/java/com/example/{mq => publish}/message/ShowRelationArtistAndGenreServiceMessage.java (92%) create mode 100644 app/api/show-api/src/main/java/com/example/publish/message/TicketingReservationServiceMessage.java rename app/infrastructure/{message_queue => message-queue}/build.gradle (100%) rename app/infrastructure/{message_queue => message-queue}/src/main/java/org/example/config/PubSubConfig.java (100%) rename app/infrastructure/{message_queue => message-queue}/src/main/java/org/example/message/ArtistSubscriptionInfraMessage.java (58%) rename app/infrastructure/{message_queue => message-queue}/src/main/java/org/example/message/GenreSubscriptionInfraMessage.java (58%) rename app/infrastructure/{message_queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java => message-queue/src/main/java/org/example/message/ReserveShowInfraMessage.java} (57%) rename app/infrastructure/{message_queue => message-queue}/src/main/java/org/example/message/ShowRelationArtistAndGenreInfraMessage.java (87%) create mode 100644 app/infrastructure/message-queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java rename app/infrastructure/{message_queue => message-queue}/src/main/java/org/example/publish/RedisMessagePublisher.java (52%) diff --git a/app/api/show-api/src/main/java/com/example/artist/service/ArtistService.java b/app/api/show-api/src/main/java/com/example/artist/service/ArtistService.java index be6a8d39..2d646b61 100644 --- a/app/api/show-api/src/main/java/com/example/artist/service/ArtistService.java +++ b/app/api/show-api/src/main/java/com/example/artist/service/ArtistService.java @@ -12,8 +12,8 @@ import com.example.artist.service.dto.response.ArtistFilterTotalCountServiceResponse; import com.example.artist.service.dto.response.ArtistSubscriptionServiceResponse; import com.example.artist.service.dto.response.ArtistUnsubscriptionServiceResponse; -import com.example.mq.MessagePublisher; -import com.example.mq.message.ArtistSubscriptionServiceMessage; +import com.example.publish.MessagePublisher; +import com.example.publish.message.ArtistSubscriptionServiceMessage; import java.util.List; import java.util.NoSuchElementException; import java.util.UUID; @@ -22,6 +22,7 @@ import org.example.entity.ArtistSubscription; import org.example.entity.artist.Artist; import org.example.usecase.ArtistSubscriptionUseCase; +import org.example.usecase.UserUseCase; import org.example.usecase.artist.ArtistUseCase; import org.springframework.stereotype.Service; @@ -32,6 +33,7 @@ public class ArtistService { private final ArtistUseCase artistUseCase; private final ArtistSubscriptionUseCase artistSubscriptionUseCase; + private final UserUseCase userUseCase; private final MessagePublisher messagePublisher; public PaginationServiceResponse searchArtist( @@ -62,22 +64,27 @@ public ArtistFilterTotalCountServiceResponse filterArtistTotalCount( } public ArtistSubscriptionServiceResponse subscribe(ArtistSubscriptionServiceRequest request) { - List existArtistsInRequest = artistUseCase.findAllArtistInIds(request.artistIds()); - List existArtistIdsInRequest = existArtistsInRequest.stream() + var existArtistsInRequest = artistUseCase.findAllArtistInIds(request.artistIds()); + var existArtistIdsInRequest = existArtistsInRequest.stream() .map(Artist::getId) .toList(); - List subscriptions = artistSubscriptionUseCase.subscribe( + var subscriptions = artistSubscriptionUseCase.subscribe( existArtistIdsInRequest, request.userId() ); - - var messages = subscriptions.stream() - .map(ArtistSubscriptionServiceMessage::from) + var subscribedArtistIds = subscriptions.stream() + .map(ArtistSubscription::getArtistId) .toList(); + + var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId()); + messagePublisher.publishArtistSubscription( "artistSubscription", - messages + ArtistSubscriptionServiceMessage.from( + userFcmToken, + subscribedArtistIds + ) ); return ArtistSubscriptionServiceResponse.builder() @@ -91,17 +98,21 @@ public ArtistSubscriptionServiceResponse subscribe(ArtistSubscriptionServiceRequ public ArtistUnsubscriptionServiceResponse unsubscribe( ArtistUnsubscriptionServiceRequest request ) { - List unsubscribedArtists = artistSubscriptionUseCase.unsubscribe( + var unsubscribedArtists = artistSubscriptionUseCase.unsubscribe( request.artistIds(), request.userId() ); - - var messages = unsubscribedArtists.stream() - .map(ArtistSubscriptionServiceMessage::from) + var unsubscribedArtistIds = unsubscribedArtists.stream() + .map(ArtistSubscription::getArtistId) .toList(); + + var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId()); messagePublisher.publishArtistSubscription( "artistUnsubscription", - messages + ArtistSubscriptionServiceMessage.from( + userFcmToken, + unsubscribedArtistIds + ) ); return ArtistUnsubscriptionServiceResponse.builder() diff --git a/app/api/show-api/src/main/java/com/example/genre/service/GenreService.java b/app/api/show-api/src/main/java/com/example/genre/service/GenreService.java index 39f2768e..94f9b6ef 100644 --- a/app/api/show-api/src/main/java/com/example/genre/service/GenreService.java +++ b/app/api/show-api/src/main/java/com/example/genre/service/GenreService.java @@ -8,8 +8,8 @@ import com.example.genre.service.dto.request.GenreUnsubscriptionServiceRequest; import com.example.genre.service.dto.response.GenreSubscriptionServiceResponse; import com.example.genre.service.dto.response.GenreUnsubscriptionServiceResponse; -import com.example.mq.MessagePublisher; -import com.example.mq.message.GenreSubscriptionServiceMessage; +import com.example.publish.MessagePublisher; +import com.example.publish.message.GenreSubscriptionServiceMessage; import java.util.List; import java.util.UUID; import lombok.RequiredArgsConstructor; @@ -18,6 +18,7 @@ import org.example.entity.GenreSubscription; import org.example.entity.genre.Genre; import org.example.usecase.GenreSubscriptionUseCase; +import org.example.usecase.UserUseCase; import org.example.usecase.genre.GenreUseCase; import org.springframework.stereotype.Service; @@ -27,25 +28,31 @@ public class GenreService { private final GenreUseCase genreUseCase; private final GenreSubscriptionUseCase genreSubscriptionUseCase; + private final UserUseCase userUseCase; private final MessagePublisher messagePublisher; public GenreSubscriptionServiceResponse subscribe(GenreSubscriptionServiceRequest request) { - List existGenresInRequest = genreUseCase.findAllGenresInIds(request.genreIds()); - List existGenreIdsInRequest = existGenresInRequest.stream() + var existGenresInRequest = genreUseCase.findAllGenresInIds(request.genreIds()); + var existGenreIdsInRequest = existGenresInRequest.stream() .map(Genre::getId) .toList(); - List subscriptions = genreSubscriptionUseCase.subscribe( + var subscriptions = genreSubscriptionUseCase.subscribe( existGenreIdsInRequest, request.userId() ); - - var messages = subscriptions.stream() - .map(GenreSubscriptionServiceMessage::from) + var subscribedGenreIds = subscriptions.stream() + .map(GenreSubscription::getGenreId) .toList(); + + var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId()); + messagePublisher.publishGenreSubscription( "genreSubscription", - messages + GenreSubscriptionServiceMessage.from( + userFcmToken, + subscribedGenreIds + ) ); return GenreSubscriptionServiceResponse.builder() @@ -60,17 +67,23 @@ public GenreSubscriptionServiceResponse subscribe(GenreSubscriptionServiceReques public GenreUnsubscriptionServiceResponse unsubscribe( GenreUnsubscriptionServiceRequest request ) { - List unsubscriptionGenres = genreSubscriptionUseCase.unsubscribe( + var unsubscriptionGenres = genreSubscriptionUseCase.unsubscribe( request.genreIds(), request.userId() ); - - var messages = unsubscriptionGenres.stream() - .map(GenreSubscriptionServiceMessage::from) + var unsubscribedGenreIds = unsubscriptionGenres + .stream() + .map(GenreSubscription::getGenreId) .toList(); + + var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId()); + messagePublisher.publishGenreSubscription( "genreUnsubscription", - messages + GenreSubscriptionServiceMessage.from( + userFcmToken, + unsubscribedGenreIds + ) ); return GenreUnsubscriptionServiceResponse.builder() diff --git a/app/api/show-api/src/main/java/com/example/mq/MessagePublisher.java b/app/api/show-api/src/main/java/com/example/mq/MessagePublisher.java deleted file mode 100644 index 4f7ed89d..00000000 --- a/app/api/show-api/src/main/java/com/example/mq/MessagePublisher.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.example.mq; - -import com.example.mq.message.ArtistSubscriptionServiceMessage; -import com.example.mq.message.GenreSubscriptionServiceMessage; -import com.example.mq.message.ShowRelationArtistAndGenreServiceMessage; -import com.example.mq.message.TicketingReservationServiceMessage; -import java.util.List; - -public interface MessagePublisher { - - void publishShow(String topic, ShowRelationArtistAndGenreServiceMessage message); - - void publishArtistSubscription(String topic, List messages); - - void publishGenreSubscription(String topic, List messages); - - void publishTicketingReservation(String topic, List messages); -} diff --git a/app/api/show-api/src/main/java/com/example/mq/message/ArtistSubscriptionServiceMessage.java b/app/api/show-api/src/main/java/com/example/mq/message/ArtistSubscriptionServiceMessage.java deleted file mode 100644 index 27c98b1e..00000000 --- a/app/api/show-api/src/main/java/com/example/mq/message/ArtistSubscriptionServiceMessage.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.example.mq.message; - -import java.util.UUID; -import lombok.Builder; -import org.example.entity.ArtistSubscription; - -@Builder -public record ArtistSubscriptionServiceMessage( - UUID userId, - UUID artistId -) { - public static ArtistSubscriptionServiceMessage from(ArtistSubscription artistSubscription) { - return ArtistSubscriptionServiceMessage.builder() - .userId(artistSubscription.getUserId()) - .artistId(artistSubscription.getArtistId()) - .build(); - } -} diff --git a/app/api/show-api/src/main/java/com/example/mq/message/GenreSubscriptionServiceMessage.java b/app/api/show-api/src/main/java/com/example/mq/message/GenreSubscriptionServiceMessage.java deleted file mode 100644 index 9b6b0380..00000000 --- a/app/api/show-api/src/main/java/com/example/mq/message/GenreSubscriptionServiceMessage.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.example.mq.message; - -import java.util.UUID; -import lombok.Builder; -import org.example.entity.GenreSubscription; - -@Builder -public record GenreSubscriptionServiceMessage( - UUID userId, - UUID genreId -) { - - public static GenreSubscriptionServiceMessage from(GenreSubscription genreSubscription) { - return GenreSubscriptionServiceMessage.builder() - .userId(genreSubscription.getUserId()) - .genreId(genreSubscription.getGenreId()) - .build(); - } -} diff --git a/app/api/show-api/src/main/java/com/example/publish/MessagePublisher.java b/app/api/show-api/src/main/java/com/example/publish/MessagePublisher.java new file mode 100644 index 00000000..f1b250a6 --- /dev/null +++ b/app/api/show-api/src/main/java/com/example/publish/MessagePublisher.java @@ -0,0 +1,17 @@ +package com.example.publish; + +import com.example.publish.message.ArtistSubscriptionServiceMessage; +import com.example.publish.message.GenreSubscriptionServiceMessage; +import com.example.publish.message.ShowRelationArtistAndGenreServiceMessage; +import com.example.publish.message.TicketingReservationServiceMessage; + +public interface MessagePublisher { + + void publishShow(String topic, ShowRelationArtistAndGenreServiceMessage message); + + void publishArtistSubscription(String topic, ArtistSubscriptionServiceMessage message); + + void publishGenreSubscription(String topic, GenreSubscriptionServiceMessage message); + + void publishTicketingReservation(String topic, TicketingReservationServiceMessage message); +} diff --git a/app/api/show-api/src/main/java/com/example/publish/message/ArtistSubscriptionServiceMessage.java b/app/api/show-api/src/main/java/com/example/publish/message/ArtistSubscriptionServiceMessage.java new file mode 100644 index 00000000..62bc8a14 --- /dev/null +++ b/app/api/show-api/src/main/java/com/example/publish/message/ArtistSubscriptionServiceMessage.java @@ -0,0 +1,22 @@ +package com.example.publish.message; + +import java.util.List; +import java.util.UUID; +import lombok.Builder; + +@Builder +public record ArtistSubscriptionServiceMessage( + String userFcmToken, + List artistIds +) { + + public static ArtistSubscriptionServiceMessage from( + String userFcmToken, + List artistIds + ) { + return ArtistSubscriptionServiceMessage.builder() + .userFcmToken(userFcmToken) + .artistIds(artistIds) + .build(); + } +} diff --git a/app/api/show-api/src/main/java/com/example/publish/message/GenreSubscriptionServiceMessage.java b/app/api/show-api/src/main/java/com/example/publish/message/GenreSubscriptionServiceMessage.java new file mode 100644 index 00000000..8cdb0fb5 --- /dev/null +++ b/app/api/show-api/src/main/java/com/example/publish/message/GenreSubscriptionServiceMessage.java @@ -0,0 +1,22 @@ +package com.example.publish.message; + +import java.util.List; +import java.util.UUID; +import lombok.Builder; + +@Builder +public record GenreSubscriptionServiceMessage( + String userFcmToken, + List genreIds +) { + + public static GenreSubscriptionServiceMessage from( + String userFcmToken, + List genreIds + ) { + return GenreSubscriptionServiceMessage.builder() + .userFcmToken(userFcmToken) + .genreIds(genreIds) + .build(); + } +} diff --git a/app/api/show-api/src/main/java/com/example/mq/message/TicketingReservationServiceMessage.java b/app/api/show-api/src/main/java/com/example/publish/message/ReserveShowServiceMessage.java similarity index 68% rename from app/api/show-api/src/main/java/com/example/mq/message/TicketingReservationServiceMessage.java rename to app/api/show-api/src/main/java/com/example/publish/message/ReserveShowServiceMessage.java index 824b157a..95ca8d53 100644 --- a/app/api/show-api/src/main/java/com/example/mq/message/TicketingReservationServiceMessage.java +++ b/app/api/show-api/src/main/java/com/example/publish/message/ReserveShowServiceMessage.java @@ -1,14 +1,13 @@ -package com.example.mq.message; +package com.example.publish.message; import com.example.show.controller.vo.TicketingApiType; import java.time.LocalDateTime; import java.util.UUID; -public record TicketingReservationServiceMessage( +public record ReserveShowServiceMessage( LocalDateTime reserveAt, String showName, TicketingApiType type, - UUID userId, UUID showId ) { diff --git a/app/api/show-api/src/main/java/com/example/mq/message/ShowRelationArtistAndGenreServiceMessage.java b/app/api/show-api/src/main/java/com/example/publish/message/ShowRelationArtistAndGenreServiceMessage.java similarity index 92% rename from app/api/show-api/src/main/java/com/example/mq/message/ShowRelationArtistAndGenreServiceMessage.java rename to app/api/show-api/src/main/java/com/example/publish/message/ShowRelationArtistAndGenreServiceMessage.java index b5d15301..74d92d7d 100644 --- a/app/api/show-api/src/main/java/com/example/mq/message/ShowRelationArtistAndGenreServiceMessage.java +++ b/app/api/show-api/src/main/java/com/example/publish/message/ShowRelationArtistAndGenreServiceMessage.java @@ -1,4 +1,4 @@ -package com.example.mq.message; +package com.example.publish.message; import java.util.List; import java.util.UUID; diff --git a/app/api/show-api/src/main/java/com/example/publish/message/TicketingReservationServiceMessage.java b/app/api/show-api/src/main/java/com/example/publish/message/TicketingReservationServiceMessage.java new file mode 100644 index 00000000..143d5a1a --- /dev/null +++ b/app/api/show-api/src/main/java/com/example/publish/message/TicketingReservationServiceMessage.java @@ -0,0 +1,10 @@ +package com.example.publish.message; + +import java.util.List; + +public record TicketingReservationServiceMessage( + String userFcmToken, + List reserveShows +) { + +} diff --git a/app/api/show-api/src/main/java/com/example/show/service/ShowAdminService.java b/app/api/show-api/src/main/java/com/example/show/service/ShowAdminService.java index d8afcafb..5946177f 100644 --- a/app/api/show-api/src/main/java/com/example/show/service/ShowAdminService.java +++ b/app/api/show-api/src/main/java/com/example/show/service/ShowAdminService.java @@ -2,8 +2,8 @@ import com.example.component.FileUploadComponent; -import com.example.mq.MessagePublisher; -import com.example.mq.message.ShowRelationArtistAndGenreServiceMessage; +import com.example.publish.MessagePublisher; +import com.example.publish.message.ShowRelationArtistAndGenreServiceMessage; import com.example.show.error.ShowError; import com.example.show.service.dto.request.ShowCreateServiceRequest; import com.example.show.service.dto.request.ShowUpdateServiceRequest; diff --git a/app/api/show-api/src/test/java/artist/service/ArtistServiceTest.java b/app/api/show-api/src/test/java/artist/service/ArtistServiceTest.java index e4b6bc32..9e0cfa5d 100644 --- a/app/api/show-api/src/test/java/artist/service/ArtistServiceTest.java +++ b/app/api/show-api/src/test/java/artist/service/ArtistServiceTest.java @@ -1,7 +1,7 @@ package artist.service; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -13,7 +13,8 @@ import com.example.artist.service.ArtistService; import com.example.artist.service.dto.request.ArtistSubscriptionServiceRequest; import com.example.artist.service.dto.request.ArtistUnsubscriptionServiceRequest; -import com.example.mq.MessagePublisher; +import com.example.publish.MessagePublisher; +import com.example.publish.message.ArtistSubscriptionServiceMessage; import java.util.List; import java.util.NoSuchElementException; import java.util.UUID; @@ -23,6 +24,7 @@ import org.example.fixture.ArtistSubscriptionFixture; import org.example.fixture.domain.ArtistFixture; import org.example.usecase.ArtistSubscriptionUseCase; +import org.example.usecase.UserUseCase; import org.example.usecase.artist.ArtistUseCase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -33,12 +35,13 @@ class ArtistServiceTest { private final ArtistSubscriptionUseCase artistSubscriptionUseCase = mock( ArtistSubscriptionUseCase.class ); - + private final UserUseCase userUseCase = mock(UserUseCase.class); private final MessagePublisher messagePublisher = mock(MessagePublisher.class); private final ArtistService artistService = new ArtistService( artistUseCase, artistSubscriptionUseCase, + userUseCase, messagePublisher ); @@ -291,7 +294,7 @@ void artistSubscribePublishMessage() { assertThat(result).isNotNull(); verify(messagePublisher, times(1)).publishArtistSubscription( eq("artistSubscription"), - anyList() + any(ArtistSubscriptionServiceMessage.class) ); } @@ -344,7 +347,7 @@ void artistUnsubscribePublishMessage() { verify(messagePublisher, times(1)) .publishArtistSubscription( eq("artistUnsubscription"), - anyList() + any(ArtistSubscriptionServiceMessage.class) ); } diff --git a/app/api/show-api/src/test/java/genre/service/GenreServiceTest.java b/app/api/show-api/src/test/java/genre/service/GenreServiceTest.java index 910cc7db..f9a0b3b2 100644 --- a/app/api/show-api/src/test/java/genre/service/GenreServiceTest.java +++ b/app/api/show-api/src/test/java/genre/service/GenreServiceTest.java @@ -1,7 +1,7 @@ package genre.service; import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyList; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.BDDMockito.given; import static org.mockito.Mockito.mock; @@ -11,7 +11,8 @@ import com.example.genre.service.GenreService; import com.example.genre.service.dto.request.GenreSubscriptionServiceRequest; import com.example.genre.service.dto.request.GenreUnsubscriptionServiceRequest; -import com.example.mq.MessagePublisher; +import com.example.publish.MessagePublisher; +import com.example.publish.message.GenreSubscriptionServiceMessage; import genre.fixture.GenreRequestDtoFixture; import genre.fixture.GenreResponseDtoFixture; import java.util.List; @@ -22,6 +23,7 @@ import org.example.fixture.GenreSubscriptionFixture; import org.example.fixture.domain.GenreFixture; import org.example.usecase.GenreSubscriptionUseCase; +import org.example.usecase.UserUseCase; import org.example.usecase.genre.GenreUseCase; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -32,11 +34,13 @@ class GenreServiceTest { private final GenreSubscriptionUseCase genreSubscriptionUseCase = mock( GenreSubscriptionUseCase.class ); + private final UserUseCase userUseCase = mock(UserUseCase.class); private final MessagePublisher messagePublisher = mock(MessagePublisher.class); private final GenreService genreService = new GenreService( genreUseCase, genreSubscriptionUseCase, + userUseCase, messagePublisher ); @@ -108,7 +112,7 @@ void genreSubscribePublishMessage() { assertThat(result).isNotNull(); verify(messagePublisher, times(1)).publishGenreSubscription( eq("genreSubscription"), - anyList() + any(GenreSubscriptionServiceMessage.class) ); } @@ -161,7 +165,7 @@ void genreUnsubscribePublishMessage() { verify(messagePublisher, times(1)) .publishGenreSubscription( eq("genreUnsubscription"), - anyList() + any(GenreSubscriptionServiceMessage.class) ); } diff --git a/app/api/show-api/src/test/java/show/service/ShowAdminServiceTest.java b/app/api/show-api/src/test/java/show/service/ShowAdminServiceTest.java index 9e3c7cf9..c16ca3ac 100644 --- a/app/api/show-api/src/test/java/show/service/ShowAdminServiceTest.java +++ b/app/api/show-api/src/test/java/show/service/ShowAdminServiceTest.java @@ -10,8 +10,8 @@ import static org.mockito.Mockito.verify; import com.example.component.FileUploadComponent; -import com.example.mq.MessagePublisher; -import com.example.mq.message.ShowRelationArtistAndGenreServiceMessage; +import com.example.publish.MessagePublisher; +import com.example.publish.message.ShowRelationArtistAndGenreServiceMessage; import com.example.show.service.ShowAdminService; import com.example.show.service.dto.request.ShowCreateServiceRequest; import com.example.show.service.dto.request.ShowUpdateServiceRequest; diff --git a/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepository.java b/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepository.java index 0ebd8e49..128ef670 100644 --- a/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepository.java +++ b/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepository.java @@ -9,4 +9,6 @@ public interface UserQuerydslRepository { Optional findUserProfileById(UUID userId); boolean existsByNickname(String nickname); + + Optional findUserFcmTokensByUserId(UUID userId); } diff --git a/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepositoryImpl.java b/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepositoryImpl.java index a84c7c03..5453c921 100644 --- a/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepositoryImpl.java +++ b/app/domain/user-domain/src/main/java/org/example/repository/user/UserQuerydslRepositoryImpl.java @@ -42,4 +42,14 @@ public boolean existsByNickname(String nickname) { .where(user.nickname.eq(nickname), user.isDeleted.isFalse()) .fetchFirst() != null; } + + @Override + public Optional findUserFcmTokensByUserId(UUID userId) { + return Optional.ofNullable(jpaQueryFactory + .select(user.fcmToken) + .from(user) + .where(user.id.eq(userId)) + .fetchOne() + ); + } } diff --git a/app/domain/user-domain/src/main/java/org/example/usecase/UserUseCase.java b/app/domain/user-domain/src/main/java/org/example/usecase/UserUseCase.java index 06e78c2c..8500f351 100644 --- a/app/domain/user-domain/src/main/java/org/example/usecase/UserUseCase.java +++ b/app/domain/user-domain/src/main/java/org/example/usecase/UserUseCase.java @@ -60,4 +60,8 @@ public void deleteUser(UUID userId) { public UserProfileDomainResponse findUserProfile(UUID userId) { return userRepository.findUserProfileById(userId).orElseThrow(NoSuchElementException::new); } + + public String findUserFcmTokensByUserId(UUID userId) { + return userRepository.findUserFcmTokensByUserId(userId).orElseThrow(NoSuchElementException::new); + } } diff --git a/app/infrastructure/build.gradle b/app/infrastructure/build.gradle index e273be43..7a77038b 100644 --- a/app/infrastructure/build.gradle +++ b/app/infrastructure/build.gradle @@ -10,5 +10,5 @@ allprojects { dependencies { implementation project(":app:infrastructure:redis") implementation project(":app:infrastructure:s3") - implementation project(":app:infrastructure:message_queue") + implementation project(":app:infrastructure:message-queue") } \ No newline at end of file diff --git a/app/infrastructure/message_queue/build.gradle b/app/infrastructure/message-queue/build.gradle similarity index 100% rename from app/infrastructure/message_queue/build.gradle rename to app/infrastructure/message-queue/build.gradle diff --git a/app/infrastructure/message_queue/src/main/java/org/example/config/PubSubConfig.java b/app/infrastructure/message-queue/src/main/java/org/example/config/PubSubConfig.java similarity index 100% rename from app/infrastructure/message_queue/src/main/java/org/example/config/PubSubConfig.java rename to app/infrastructure/message-queue/src/main/java/org/example/config/PubSubConfig.java diff --git a/app/infrastructure/message_queue/src/main/java/org/example/message/ArtistSubscriptionInfraMessage.java b/app/infrastructure/message-queue/src/main/java/org/example/message/ArtistSubscriptionInfraMessage.java similarity index 58% rename from app/infrastructure/message_queue/src/main/java/org/example/message/ArtistSubscriptionInfraMessage.java rename to app/infrastructure/message-queue/src/main/java/org/example/message/ArtistSubscriptionInfraMessage.java index 526b611c..1eb34a47 100644 --- a/app/infrastructure/message_queue/src/main/java/org/example/message/ArtistSubscriptionInfraMessage.java +++ b/app/infrastructure/message-queue/src/main/java/org/example/message/ArtistSubscriptionInfraMessage.java @@ -1,21 +1,22 @@ package org.example.message; -import com.example.mq.message.ArtistSubscriptionServiceMessage; +import com.example.publish.message.ArtistSubscriptionServiceMessage; +import java.util.List; import java.util.UUID; import lombok.Builder; @Builder public record ArtistSubscriptionInfraMessage( - UUID userId, - UUID artistId + String userFcmToken, + List artistIds ) { public static ArtistSubscriptionInfraMessage from( ArtistSubscriptionServiceMessage message ) { return ArtistSubscriptionInfraMessage.builder() - .userId(message.userId()) - .artistId(message.artistId()) + .userFcmToken(message.userFcmToken()) + .artistIds(message.artistIds()) .build(); } } diff --git a/app/infrastructure/message_queue/src/main/java/org/example/message/GenreSubscriptionInfraMessage.java b/app/infrastructure/message-queue/src/main/java/org/example/message/GenreSubscriptionInfraMessage.java similarity index 58% rename from app/infrastructure/message_queue/src/main/java/org/example/message/GenreSubscriptionInfraMessage.java rename to app/infrastructure/message-queue/src/main/java/org/example/message/GenreSubscriptionInfraMessage.java index 5ecc6c6a..f117d3ea 100644 --- a/app/infrastructure/message_queue/src/main/java/org/example/message/GenreSubscriptionInfraMessage.java +++ b/app/infrastructure/message-queue/src/main/java/org/example/message/GenreSubscriptionInfraMessage.java @@ -1,21 +1,22 @@ package org.example.message; -import com.example.mq.message.GenreSubscriptionServiceMessage; +import com.example.publish.message.GenreSubscriptionServiceMessage; +import java.util.List; import java.util.UUID; import lombok.Builder; @Builder public record GenreSubscriptionInfraMessage( - UUID userId, - UUID genreId + String userFcmToken, + List genreIds ) { public static GenreSubscriptionInfraMessage from( GenreSubscriptionServiceMessage message ) { return GenreSubscriptionInfraMessage.builder() - .userId(message.userId()) - .genreId(message.genreId()) + .userFcmToken(message.userFcmToken()) + .genreIds(message.genreIds()) .build(); } } diff --git a/app/infrastructure/message_queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java b/app/infrastructure/message-queue/src/main/java/org/example/message/ReserveShowInfraMessage.java similarity index 57% rename from app/infrastructure/message_queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java rename to app/infrastructure/message-queue/src/main/java/org/example/message/ReserveShowInfraMessage.java index dacf155e..6bd37c2b 100644 --- a/app/infrastructure/message_queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java +++ b/app/infrastructure/message-queue/src/main/java/org/example/message/ReserveShowInfraMessage.java @@ -1,29 +1,25 @@ package org.example.message; -import com.example.mq.message.TicketingReservationServiceMessage; +import com.example.publish.message.ReserveShowServiceMessage; import com.example.show.controller.vo.TicketingApiType; import java.time.LocalDateTime; import java.util.UUID; import lombok.Builder; @Builder -public record TicketingReservationInfraMessage( +public record ReserveShowInfraMessage( LocalDateTime reserveAt, String showName, TicketingApiType type, - UUID userId, UUID showId ) { - - public static TicketingReservationInfraMessage from( - TicketingReservationServiceMessage message - ) { - return TicketingReservationInfraMessage.builder() + public static ReserveShowInfraMessage from(ReserveShowServiceMessage message) { + return ReserveShowInfraMessage.builder() .reserveAt(message.reserveAt()) .showName(message.showName()) .type(message.type()) - .userId(message.userId()) .showId(message.showId()) .build(); } + } diff --git a/app/infrastructure/message_queue/src/main/java/org/example/message/ShowRelationArtistAndGenreInfraMessage.java b/app/infrastructure/message-queue/src/main/java/org/example/message/ShowRelationArtistAndGenreInfraMessage.java similarity index 87% rename from app/infrastructure/message_queue/src/main/java/org/example/message/ShowRelationArtistAndGenreInfraMessage.java rename to app/infrastructure/message-queue/src/main/java/org/example/message/ShowRelationArtistAndGenreInfraMessage.java index aa7a0bf7..69cc5a99 100644 --- a/app/infrastructure/message_queue/src/main/java/org/example/message/ShowRelationArtistAndGenreInfraMessage.java +++ b/app/infrastructure/message-queue/src/main/java/org/example/message/ShowRelationArtistAndGenreInfraMessage.java @@ -1,6 +1,6 @@ package org.example.message; -import com.example.mq.message.ShowRelationArtistAndGenreServiceMessage; +import com.example.publish.message.ShowRelationArtistAndGenreServiceMessage; import java.util.List; import java.util.UUID; import lombok.Builder; diff --git a/app/infrastructure/message-queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java b/app/infrastructure/message-queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java new file mode 100644 index 00000000..0b9be9bf --- /dev/null +++ b/app/infrastructure/message-queue/src/main/java/org/example/message/TicketingReservationInfraMessage.java @@ -0,0 +1,25 @@ +package org.example.message; + +import com.example.publish.message.TicketingReservationServiceMessage; +import java.util.List; +import lombok.Builder; + +@Builder +public record TicketingReservationInfraMessage( + String userFcmToken, + List reserveShows +) { + + public static TicketingReservationInfraMessage from( + TicketingReservationServiceMessage message + ) { + return TicketingReservationInfraMessage.builder() + .userFcmToken(message.userFcmToken()) + .reserveShows(message.reserveShows() + .stream() + .map(ReserveShowInfraMessage::from) + .toList() + ) + .build(); + } +} diff --git a/app/infrastructure/message_queue/src/main/java/org/example/publish/RedisMessagePublisher.java b/app/infrastructure/message-queue/src/main/java/org/example/publish/RedisMessagePublisher.java similarity index 52% rename from app/infrastructure/message_queue/src/main/java/org/example/publish/RedisMessagePublisher.java rename to app/infrastructure/message-queue/src/main/java/org/example/publish/RedisMessagePublisher.java index 23e529f5..c9cf6df2 100644 --- a/app/infrastructure/message_queue/src/main/java/org/example/publish/RedisMessagePublisher.java +++ b/app/infrastructure/message-queue/src/main/java/org/example/publish/RedisMessagePublisher.java @@ -1,11 +1,10 @@ package org.example.publish; -import com.example.mq.MessagePublisher; -import com.example.mq.message.ArtistSubscriptionServiceMessage; -import com.example.mq.message.GenreSubscriptionServiceMessage; -import com.example.mq.message.ShowRelationArtistAndGenreServiceMessage; -import com.example.mq.message.TicketingReservationServiceMessage; -import java.util.List; +import com.example.publish.MessagePublisher; +import com.example.publish.message.ArtistSubscriptionServiceMessage; +import com.example.publish.message.GenreSubscriptionServiceMessage; +import com.example.publish.message.ShowRelationArtistAndGenreServiceMessage; +import com.example.publish.message.TicketingReservationServiceMessage; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.example.message.ArtistSubscriptionInfraMessage; @@ -24,53 +23,46 @@ public class RedisMessagePublisher implements MessagePublisher { @Override public void publishShow(String topic, ShowRelationArtistAndGenreServiceMessage message) { - template.convertAndSend(topic, ShowRelationArtistAndGenreInfraMessage.from(message)); + var infraMessage = ShowRelationArtistAndGenreInfraMessage.from(message); + + template.convertAndSend(topic, infraMessage); log.info("Message published successfully to topic: {}", topic); - log.info("Message Contents ( artistIds : {}, genreIds : {} )", - message.artistIds(), - message.genreIds() - ); + log.info("Message Contents ( showRelationArtistAndGenreInfraMessage : {})", infraMessage); } @Override public void publishArtistSubscription( String topic, - List messages + ArtistSubscriptionServiceMessage message ) { - var infraMessages = messages.stream() - .map(ArtistSubscriptionInfraMessage::from) - .toList(); + var infraMessage = ArtistSubscriptionInfraMessage.from(message); - template.convertAndSend(topic, infraMessages); + template.convertAndSend(topic, infraMessage); log.info("Message published successfully to topic: {}", topic); - log.info("Message Contents ( artistSubscriptionMessage : {} )", infraMessages); + log.info("Message Contents ( artistSubscriptionMessage : {} )", infraMessage); } @Override public void publishGenreSubscription( String topic, - List messages + GenreSubscriptionServiceMessage message ) { - var infraMessages = messages.stream() - .map(GenreSubscriptionInfraMessage::from) - .toList(); + var infraMessage = GenreSubscriptionInfraMessage.from(message); - template.convertAndSend(topic, infraMessages); + template.convertAndSend(topic, infraMessage); log.info("Message published successfully to topic: {}", topic); - log.info("Message Contents ( genreSubscriptionMessage : {} )", infraMessages); + log.info("Message Contents ( genreSubscriptionMessage : {} )", infraMessage); } @Override public void publishTicketingReservation( String topic, - List messages + TicketingReservationServiceMessage message ) { - var infraMessages = messages.stream() - .map(TicketingReservationInfraMessage::from) - .toList(); + var infraMessage = TicketingReservationInfraMessage.from(message); - template.convertAndSend(topic, infraMessages); + template.convertAndSend(topic, infraMessage); log.info("Message published successfully to topic: {}", topic); - log.info("Message Contents ( ticketingReservationMessage : {} )", infraMessages); + log.info("Message Contents ( ticketingReservationMessage : {} )", infraMessage); } } diff --git a/settings.gradle b/settings.gradle index 9ebd3974..ce933767 100644 --- a/settings.gradle +++ b/settings.gradle @@ -17,4 +17,4 @@ include(":app:api:show-api") include (":app:infrastructure") include (":app:infrastructure:redis") include (":app:infrastructure:s3") -include (":app:infrastructure:message_queue") \ No newline at end of file +include (":app:infrastructure:message-queue") \ No newline at end of file