Skip to content

Commit

Permalink
fix: 장르, 아티스트 구독 시 FCM 알림, 공연 연관 구독 FCM 알림 연동 (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 26, 2024
1 parent 4f1b1f3 commit 958c969
Show file tree
Hide file tree
Showing 55 changed files with 716 additions and 201 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example;

import org.example.service.dto.MultipleTargetMessageServiceRequest;
import org.example.service.dto.SingleTargetMessageServiceRequest;

public interface SubscriptionMessage {

void send(SingleTargetMessageServiceRequest request);

void send(MultipleTargetMessageServiceRequest request);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class SubscriptionMessageConverter {

private static final ObjectMapper objectMapper = new ObjectMapper();

public static ShowRelationSubscriptionMessageApiRequest toShowRelationSubscriptionMessage(
Message message) {
public static ShowRelationSubscriptionMessageApiRequest toShowRelationSubscriptionMessage(Message message) {
try {
var convertedMessage = objectMapper.readValue(
message.getBody(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example.listener.dto;

import java.util.UUID;
import org.example.service.dto.ArtistMessageServiceRequest;

public record ArtistMessageApiRequest(
UUID artistId,
String artistName
) {

public ArtistMessageServiceRequest toServiceRequest() {
return ArtistMessageServiceRequest.builder()
.artistId(artistId)
.artistName(artistName)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.example.listener.dto;

import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.service.dto.ArtistSubscriptionMessageServiceRequest;

@Builder
public record ArtistSubscriptionMessageApiRequest(
String userFcmToken,
List<UUID> artistIds
List<ArtistMessageApiRequest> artists
) {

public ArtistSubscriptionMessageServiceRequest toServiceRequest() {
return ArtistSubscriptionMessageServiceRequest.builder()
.userFcmToken(userFcmToken)
.artistIds(artistIds)
.artists(artists.stream().map(ArtistMessageApiRequest::toServiceRequest).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.example.listener.dto;

import java.util.UUID;
import org.example.service.dto.GenreMessageServiceRequest;

public record GenreMessageApiRequest(
UUID genreId,
String genreName
) {

public GenreMessageServiceRequest toServiceRequest() {
return GenreMessageServiceRequest.builder()
.genreId(genreId)
.genreName(genreName)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.example.listener.dto;

import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.service.dto.GenreSubscriptionMessageServiceRequest;

@Builder
public record GenreSubscriptionMessageApiRequest(
String userFcmToken,
List<UUID> genreIds
List<GenreMessageApiRequest> genres
) {

public GenreSubscriptionMessageServiceRequest toServiceRequest() {
return GenreSubscriptionMessageServiceRequest.builder()
.userFcmToken(userFcmToken)
.genreIds(genreIds)
.genres(genres.stream().map(GenreMessageApiRequest::toServiceRequest).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
package org.example.service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.example.SubscriptionMessage;
import org.example.dto.response.ArtistSubscriptionDomainResponse;
import org.example.dto.response.GenreSubscriptionDomainResponse;
import org.example.message.MessageParam;
import org.example.message.PushMessageTemplate;
import org.example.service.dto.ArtistSubscriptionMessageServiceRequest;
import org.example.service.dto.GenreSubscriptionMessageServiceRequest;
import org.example.service.dto.MultipleTargetMessageServiceRequest;
import org.example.service.dto.SubscriptionMessageServiceRequest;
import org.example.usecase.ArtistSubscriptionUseCase;
import org.example.usecase.GenreSubscriptionUseCase;
Expand All @@ -14,16 +23,43 @@ public class SubscriptionAlarmService {

private final ArtistSubscriptionUseCase artistSubscriptionUseCase;
private final GenreSubscriptionUseCase genreSubscriptionUseCase;
private final SubscriptionMessage subscriptionMessage;


public void showRelationSubscription(SubscriptionMessageServiceRequest request) {
var artistSubscribedUserFcmTokens = artistSubscriptionUseCase.findUserFcmTokensByArtistIds(request.artistIds());
System.out.println(artistSubscribedUserFcmTokens);
//Todo 아티스트 구독한 user들에게 FCM 알림 요청
var artistSubscriptions = artistSubscriptionUseCase.findArtistSubscriptionsByArtistIds(request.artistIds());
Map<String, List<String>> artistSubscriptionsMap = artistSubscriptions.stream()
.collect(Collectors.groupingBy(
ArtistSubscriptionDomainResponse::artistName,
Collectors.mapping(
ArtistSubscriptionDomainResponse::userFcmToken,
Collectors.toList()
)
));
for (Map.Entry<String, List<String>> entry : artistSubscriptionsMap.entrySet()) {
String artistName = entry.getKey();
List<String> fcmTokens = entry.getValue();
MessageParam message = PushMessageTemplate.getSubscribedArtistVisitKoreaAlertMessage(artistName);

var genreSubscribedUserFcmTokens = genreSubscriptionUseCase.findUserFcmTokensByGenreIds(request.genreIds());
System.out.println(genreSubscribedUserFcmTokens);
//Todo 장르 구독한 user들에게 FCM 알림 요청
subscriptionMessage.send(MultipleTargetMessageServiceRequest.of(fcmTokens, message));
}

var genreSubscriptions = genreSubscriptionUseCase.findGenreSubscriptionsByGenreIds(request.genreIds());
Map<String, List<String>> genreSubscriptionsMap = genreSubscriptions.stream()
.collect(Collectors.groupingBy(
GenreSubscriptionDomainResponse::genreName,
Collectors.mapping(
GenreSubscriptionDomainResponse::userFcmToken,
Collectors.toList()
)
));
for (Map.Entry<String, List<String>> entry : genreSubscriptionsMap.entrySet()) {
String genreName = entry.getKey();
List<String> fcmTokens = entry.getValue();
MessageParam message = PushMessageTemplate.getSubscribedGenreVisitKoreaAlertMessage(genreName);

subscriptionMessage.send(MultipleTargetMessageServiceRequest.of(fcmTokens, message));
}
}

public void artistSubscribe(ArtistSubscriptionMessageServiceRequest request) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.example.service.dto;

import java.util.UUID;
import lombok.Builder;
import org.example.dto.request.ArtistMessageDomainRequest;

@Builder
public record ArtistMessageServiceRequest(
UUID artistId,
String artistName
) {
public ArtistMessageDomainRequest toDomainRequest() {
return ArtistMessageDomainRequest.builder()
.artistId(artistId)
.artistName(artistName)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.example.service.dto;

import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.dto.ArtistSubscriptionMessageDomainRequest;
import org.example.dto.request.ArtistSubscriptionMessageDomainRequest;

@Builder
public record ArtistSubscriptionMessageServiceRequest(
String userFcmToken,
List<UUID> artistIds
List<ArtistMessageServiceRequest> artists
) {

public ArtistSubscriptionMessageDomainRequest toDomainRequest() {
return ArtistSubscriptionMessageDomainRequest.builder()
.userFcmToken(userFcmToken)
.artistIds(artistIds)
.artists(artists.stream().map(ArtistMessageServiceRequest::toDomainRequest).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example.service.dto;

import java.util.UUID;
import lombok.Builder;
import org.example.dto.request.GenreMessageDomainRequest;

@Builder
public record GenreMessageServiceRequest(
UUID genreId,
String genreName
) {

public GenreMessageDomainRequest toDomainRequest() {
return GenreMessageDomainRequest.builder()
.genreId(genreId)
.genreName(genreName)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
package org.example.service.dto;

import java.util.List;
import java.util.UUID;
import lombok.Builder;
import org.example.dto.GenreSubscriptionMessageDomainRequest;
import org.example.dto.request.GenreSubscriptionMessageDomainRequest;

@Builder
public record GenreSubscriptionMessageServiceRequest(
String userFcmToken,
List<UUID> genreIds
List<GenreMessageServiceRequest> genres
) {

public GenreSubscriptionMessageDomainRequest toDomainRequest() {
return GenreSubscriptionMessageDomainRequest.builder()
.userFcmToken(userFcmToken)
.genreIds(genreIds)
.genres(genres.stream().map(GenreMessageServiceRequest::toDomainRequest).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.example.service.dto;

import java.util.List;
import lombok.Builder;
import org.example.message.MessageParam;

@Builder
public record MultipleTargetMessageServiceRequest(
List<String> fcmTokens,
MessageParam message
) {
public static MultipleTargetMessageServiceRequest of(
List<String> fcmTokens,
MessageParam message
) {
return MultipleTargetMessageServiceRequest.builder()
.fcmTokens(fcmTokens)
.message(message)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.example.service.dto;

import org.example.message.MessageParam;

public record SingleTargetMessageServiceRequest(
String fcmToken,
MessageParam message
) {

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.example.listener.dto;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import org.example.service.dto.request.TicketingReservationMessageServiceRequest;
Expand All @@ -9,17 +8,17 @@ public record TicketingReservationMessageApiRequest(
String userFcmToken,
String name,
UUID showId,
List<String> addAts,
List<String> deleteAts
List<TicketingTimeMessageApiRequest> addAts,
List<TicketingTimeMessageApiRequest> deleteAts
) {

public TicketingReservationMessageServiceRequest toServiceRequest() {
return TicketingReservationMessageServiceRequest.builder()
.userFcmToken(userFcmToken)
.name(name)
.showId(showId)
.addAts(addAts.stream().map(LocalDateTime::parse).toList())
.deleteAts(deleteAts.stream().map(LocalDateTime::parse).toList())
.addAts(addAts.stream().map(TicketingTimeMessageApiRequest::toServiceRequest).toList())
.deleteAts(deleteAts.stream().map(TicketingTimeMessageApiRequest::toServiceRequest).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.example.listener.dto;

import java.time.LocalDateTime;
import lombok.Builder;
import org.example.service.dto.request.TicketingTimeMessageServiceRequest;
import org.example.vo.TicketingAlertTimeApiType;

@Builder
public record TicketingTimeMessageApiRequest(
String alertAt,
TicketingAlertTimeApiType time
) {

public TicketingTimeMessageServiceRequest toServiceRequest() {
return TicketingTimeMessageServiceRequest.builder()
.alertAt(LocalDateTime.parse(alertAt))
.time(time)
.build();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public class TicketingAlertService {
private final TicketingAlertBatch ticketingAlertBatchComponent;

public void reserveTicketingAlert(TicketingReservationMessageServiceRequest request) {
TicketingAlertToSchedulerDomainResponse ticketingAlertToScheduler = ticketingAlertUseCase.reserveTicketingAlert(
request.toDomainRequest());
TicketingAlertToSchedulerDomainResponse ticketingAlertToScheduler = ticketingAlertUseCase
.reserveTicketingAlert(request.toDomainRequest());

ticketingAlertBatchComponent.reserveTicketingAlerts(
TicketingAlertServiceResponse.from(ticketingAlertToScheduler)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.example.service.dto.request;

import java.time.LocalDateTime;
import java.util.List;
import java.util.UUID;
import lombok.Builder;
Expand All @@ -11,17 +10,17 @@ public record TicketingReservationMessageServiceRequest(
String userFcmToken,
String name,
UUID showId,
List<LocalDateTime> addAts,
List<LocalDateTime> deleteAts
List<TicketingTimeMessageServiceRequest> addAts,
List<TicketingTimeMessageServiceRequest> deleteAts
) {

public TicketingReservationMessageDomainRequest toDomainRequest() {
return TicketingReservationMessageDomainRequest.builder()
.userFcmToken(userFcmToken)
.name(name)
.showId(showId)
.addAts(addAts)
.deleteAts(deleteAts)
.addAts(addAts.stream().map(TicketingTimeMessageServiceRequest::toDomainRequest).toList())
.deleteAts(deleteAts.stream().map(TicketingTimeMessageServiceRequest::toDomainRequest).toList())
.build();
}
}
Loading

0 comments on commit 958c969

Please sign in to comment.