Skip to content

Commit

Permalink
fix: 구독 알림 메시지 Publish 필드 누락 (#128)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Aug 25, 2024
1 parent 9a19e6e commit 94d13db
Show file tree
Hide file tree
Showing 14 changed files with 128 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public record ArtistSearchPaginationApiParam(
String englishName,

@Schema(description = "아티스트 구독 여부")
boolean isSubscribe
boolean isSubscribed
) {

public static ArtistSearchPaginationApiParam from(ArtistSearchPaginationServiceParam param) {
Expand All @@ -27,7 +27,7 @@ public static ArtistSearchPaginationApiParam from(ArtistSearchPaginationServiceP
param.artistImageUrl(),
param.artistKoreanName(),
param.artistEnglishName(),
param.isSubscribe()
param.isSubscribed()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import com.example.artist.service.dto.response.ArtistSubscriptionServiceResponse;
import com.example.artist.service.dto.response.ArtistUnsubscriptionServiceResponse;
import com.example.publish.MessagePublisher;
import com.example.publish.message.ArtistServiceMessage;
import com.example.publish.message.ArtistSubscriptionServiceMessage;
import java.util.List;
import java.util.NoSuchElementException;
Expand Down Expand Up @@ -90,13 +91,16 @@ public ArtistSubscriptionServiceResponse subscribe(ArtistSubscriptionServiceRequ
.map(ArtistSubscription::getArtistId)
.toList();

var subscribedArtistMessage = artistUseCase.findAllArtistInIds(subscribedArtistIds)
.stream().map(ArtistServiceMessage::from)
.toList();
var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());

messagePublisher.publishArtistSubscription(
"artistSubscription",
ArtistSubscriptionServiceMessage.from(
userFcmToken,
subscribedArtistIds
subscribedArtistMessage
)
);

Expand All @@ -115,16 +119,18 @@ public ArtistUnsubscriptionServiceResponse unsubscribe(
request.artistIds(),
request.userId()
);
var unsubscribedArtistIds = unsubscribedArtists.stream()
.map(ArtistSubscription::getArtistId)
var unsubscribedArtistMessage = unsubscribedArtists.stream()
.map(ArtistServiceMessage::toUnsubscribe)
.toList();


var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());

messagePublisher.publishArtistSubscription(
"artistUnsubscription",
ArtistSubscriptionServiceMessage.from(
userFcmToken,
unsubscribedArtistIds
unsubscribedArtistMessage
)
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ public record ArtistSearchPaginationServiceParam(
String artistImageUrl,
String artistKoreanName,
String artistEnglishName,
boolean isSubscribe
boolean isSubscribed
) {

public static ArtistSearchPaginationServiceParam from(
ArtistSimpleDomainResponse response,
List<UUID> artistSubscriptions
) {
boolean isSubscribe = artistSubscriptions.contains(response.id());
boolean isSubscribed = artistSubscriptions.contains(response.id());

return ArtistSearchPaginationServiceParam.builder()
.artistId(response.id())
.artistImageUrl(response.image())
.artistKoreanName(response.koreanName())
.artistEnglishName(response.englishName())
.isSubscribe(isSubscribe)
.isSubscribed(isSubscribed)
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.example.genre.service.dto.response.GenreSubscriptionServiceResponse;
import com.example.genre.service.dto.response.GenreUnsubscriptionServiceResponse;
import com.example.publish.MessagePublisher;
import com.example.publish.message.GenreServiceMessage;
import com.example.publish.message.GenreSubscriptionServiceMessage;
import java.util.List;
import java.util.UUID;
Expand Down Expand Up @@ -45,13 +46,16 @@ public GenreSubscriptionServiceResponse subscribe(GenreSubscriptionServiceReques
.map(GenreSubscription::getGenreId)
.toList();

var subscribedGenreMessage = genreUseCase.findAllGenresInIds(subscribedGenreIds)
.stream().map(GenreServiceMessage::from)
.toList();
var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());

messagePublisher.publishGenreSubscription(
"genreSubscription",
GenreSubscriptionServiceMessage.from(
userFcmToken,
subscribedGenreIds
subscribedGenreMessage
)
);

Expand All @@ -71,9 +75,8 @@ public GenreUnsubscriptionServiceResponse unsubscribe(
request.genreIds(),
request.userId()
);
var unsubscribedGenreIds = unsubscriptionGenres
.stream()
.map(GenreSubscription::getGenreId)
var unsubscribedGenreMessage = unsubscriptionGenres.stream()
.map(GenreServiceMessage::toUnsubscribe)
.toList();

var userFcmToken = userUseCase.findUserFcmTokensByUserId(request.userId());
Expand All @@ -82,7 +85,7 @@ public GenreUnsubscriptionServiceResponse unsubscribe(
"genreUnsubscription",
GenreSubscriptionServiceMessage.from(
userFcmToken,
unsubscribedGenreIds
unsubscribedGenreMessage
)
);

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

import java.util.UUID;
import lombok.Builder;
import org.example.entity.ArtistSubscription;
import org.example.entity.artist.Artist;

@Builder
public record ArtistServiceMessage(
UUID id,
String name
) {

public static ArtistServiceMessage from(Artist artist) {
return ArtistServiceMessage.builder()
.id(artist.getId())
.name(artist.getEnglishName())
.build();
}

public static ArtistServiceMessage toUnsubscribe(ArtistSubscription artistSubscription) {
return ArtistServiceMessage.builder()
.id(artistSubscription.getArtistId())
.name("empty")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
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
List<ArtistServiceMessage> artists
) {

public static ArtistSubscriptionServiceMessage from(
String userFcmToken,
List<UUID> artistIds
List<ArtistServiceMessage> artists
) {
return ArtistSubscriptionServiceMessage.builder()
.userFcmToken(userFcmToken)
.artistIds(artistIds)
.artists(artists)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.example.publish.message;

import java.util.UUID;
import lombok.Builder;
import org.example.entity.GenreSubscription;
import org.example.entity.genre.Genre;

@Builder
public record GenreServiceMessage(
UUID id,
String name
) {

public static GenreServiceMessage from(Genre genre) {
return GenreServiceMessage.builder()
.id(genre.getId())
.name(genre.getName())
.build();
}

public static GenreServiceMessage toUnsubscribe(GenreSubscription genreSubscription) {
return GenreServiceMessage.builder()
.id(genreSubscription.getGenreId())
.name("empty")
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
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
List<GenreServiceMessage> genres
) {

public static GenreSubscriptionServiceMessage from(
String userFcmToken,
List<UUID> genreIds
List<GenreServiceMessage> genres
) {
return GenreSubscriptionServiceMessage.builder()
.userFcmToken(userFcmToken)
.genreIds(genreIds)
.genres(genres)
.build();
}
}
2 changes: 2 additions & 0 deletions app/domain/common-domain/src/main/resources/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ create table alarm.artist_subscription
created_at timestamp(3) not null,
updated_at timestamp(3) not null,
artist_id uuid not null,
artist_name varchar(255) not null,
id uuid not null,
user_fcm_token varchar(255) not null,
primary key (id)
Expand All @@ -260,6 +261,7 @@ create table alarm.genre_subscription
created_at timestamp(3) not null,
updated_at timestamp(3) not null,
genre_id uuid not null,
genre_name varchar(255) not null,
id uuid not null,
user_fcm_token varchar(255) not null,
primary key (id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,7 @@ public void save(
var showGenres = show.toShowGenre(request.genreIds());
showGenreRepository.saveAll(showGenres);

var showTicketingTimes = show.toShowTicketingTime(
request.showTicketingTimes());
var showTicketingTimes = show.toShowTicketingTime(request.showTicketingTimes());
showTicketingTimeRepository.saveAll(showTicketingTimes);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example.message;

import com.example.publish.message.ArtistServiceMessage;
import java.util.UUID;
import lombok.Builder;

@Builder
public record ArtistInfraMessage(
UUID artistId,
String artistName
) {

public static ArtistInfraMessage from(ArtistServiceMessage message) {
return ArtistInfraMessage.builder()
.artistId(message.id())
.artistName(message.name())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import com.example.publish.message.ArtistSubscriptionServiceMessage;
import java.util.List;
import java.util.UUID;
import lombok.Builder;

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

public static ArtistSubscriptionInfraMessage from(
ArtistSubscriptionServiceMessage message
) {
return ArtistSubscriptionInfraMessage.builder()
.userFcmToken(message.userFcmToken())
.artistIds(message.artistIds())
.artists(message.artists().stream().map(ArtistInfraMessage::from).toList())
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.example.message;

import com.example.publish.message.GenreServiceMessage;
import java.util.UUID;
import lombok.Builder;

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

public static GenreInfraMessage from(GenreServiceMessage message) {
return GenreInfraMessage.builder()
.genreId(message.id())
.genreName(message.name())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,20 @@

import com.example.publish.message.GenreSubscriptionServiceMessage;
import java.util.List;
import java.util.UUID;
import lombok.Builder;

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

public static GenreSubscriptionInfraMessage from(
GenreSubscriptionServiceMessage message
) {
return GenreSubscriptionInfraMessage.builder()
.userFcmToken(message.userFcmToken())
.genreIds(message.genreIds())
.genres(message.genres().stream().map(GenreInfraMessage::from).toList())
.build();
}
}

0 comments on commit 94d13db

Please sign in to comment.