Skip to content

Commit

Permalink
fix : redis sub request (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 12, 2024
1 parent 7431d73 commit 559ed4b
Show file tree
Hide file tree
Showing 28 changed files with 228 additions and 151 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<ArtistSearchPaginationServiceParam> searchArtist(
Expand Down Expand Up @@ -62,22 +64,27 @@ public ArtistFilterTotalCountServiceResponse filterArtistTotalCount(
}

public ArtistSubscriptionServiceResponse subscribe(ArtistSubscriptionServiceRequest request) {
List<Artist> existArtistsInRequest = artistUseCase.findAllArtistInIds(request.artistIds());
List<UUID> existArtistIdsInRequest = existArtistsInRequest.stream()
var existArtistsInRequest = artistUseCase.findAllArtistInIds(request.artistIds());
var existArtistIdsInRequest = existArtistsInRequest.stream()
.map(Artist::getId)
.toList();

List<ArtistSubscription> 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()
Expand All @@ -91,17 +98,21 @@ public ArtistSubscriptionServiceResponse subscribe(ArtistSubscriptionServiceRequ
public ArtistUnsubscriptionServiceResponse unsubscribe(
ArtistUnsubscriptionServiceRequest request
) {
List<ArtistSubscription> 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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -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<Genre> existGenresInRequest = genreUseCase.findAllGenresInIds(request.genreIds());
List<UUID> existGenreIdsInRequest = existGenresInRequest.stream()
var existGenresInRequest = genreUseCase.findAllGenresInIds(request.genreIds());
var existGenreIdsInRequest = existGenresInRequest.stream()
.map(Genre::getId)
.toList();

List<GenreSubscription> 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()
Expand All @@ -60,17 +67,23 @@ public GenreSubscriptionServiceResponse subscribe(GenreSubscriptionServiceReques
public GenreUnsubscriptionServiceResponse unsubscribe(
GenreUnsubscriptionServiceRequest request
) {
List<GenreSubscription> 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()
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -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<UUID> artistIds
) {

public static ArtistSubscriptionServiceMessage from(
String userFcmToken,
List<UUID> artistIds
) {
return ArtistSubscriptionServiceMessage.builder()
.userFcmToken(userFcmToken)
.artistIds(artistIds)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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<UUID> genreIds
) {

public static GenreSubscriptionServiceMessage from(
String userFcmToken,
List<UUID> genreIds
) {
return GenreSubscriptionServiceMessage.builder()
.userFcmToken(userFcmToken)
.genreIds(genreIds)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -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
) {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.example.mq.message;
package com.example.publish.message;

import java.util.List;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.publish.message;

import java.util.List;

public record TicketingReservationServiceMessage(
String userFcmToken,
List<ReserveShowServiceMessage> reserveShows
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 559ed4b

Please sign in to comment.