Skip to content

Commit

Permalink
fix : 알림 데이터베이스 showID 스키마 추가 (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
GaBaljaintheroom authored Nov 11, 2024
1 parent 8dcd822 commit b43616f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Builder
public record ShowAlarmPaginationApiParam(
UUID id,
UUID showId,
String title,
String content,
LocalDateTime createAt
Expand All @@ -16,6 +17,7 @@ public record ShowAlarmPaginationApiParam(
public static ShowAlarmPaginationApiParam from(ShowAlarmPaginationServiceParam param) {
return ShowAlarmPaginationApiParam.builder()
.id(param.id())
.showId(param.showId())
.title(param.title())
.content(param.content())
.createAt(param.createAt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
@Builder
public record ShowAlarmPaginationServiceParam(
UUID id,
UUID showId,
String title,
String content,
LocalDateTime createAt
Expand All @@ -16,6 +17,7 @@ public record ShowAlarmPaginationServiceParam(
public static ShowAlarmPaginationServiceParam from(ShowAlarmDomainResponse response) {
return ShowAlarmPaginationServiceParam.builder()
.id(response.id())
.showId(response.showId())
.title(response.title())
.content(response.content())
.createAt(response.createAt())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,61 +9,33 @@
import org.springframework.data.redis.connection.Message;

@Slf4j
public class SubscriptionMessageConverter {
public final class SubscriptionMessageConverter {

private SubscriptionMessageConverter() {
}

private static final ObjectMapper objectMapper = new ObjectMapper();

public static ShowRelationSubscriptionMessageApiRequest toShowRelationSubscriptionMessage(Message message) {
try {
var convertedMessage = objectMapper.readValue(
message.getBody(),
ShowRelationSubscriptionMessageApiRequest.class
);
log.info("Message published successfully to topic: {}",
new String(message.getChannel()));
log.info(
"Subscribe Message Contents ( ShowRelationSubscriptionMessageApiRequest : {} )",
message);

return convertedMessage;
} catch (IOException e) {
log.error("Failed to convert message to ShowRelationSubscriptionMessageApiRequest", e);
throw new IllegalArgumentException("메시지를 받지 못했습니다.");
}
return convertMessage(message, ShowRelationSubscriptionMessageApiRequest.class);
}

public static ArtistSubscriptionMessageApiRequest toArtistSubscriptionMessage(Message message) {
try {
var convertedMessage = objectMapper.readValue(
message.getBody(),
ArtistSubscriptionMessageApiRequest.class
);
log.info("Message published successfully to topic: {}",
new String(message.getChannel()));
log.info("Subscribe Message Contents ( ArtistSubscriptionMessageApiRequest : {} )",
message);

return convertedMessage;
} catch (IOException e) {
log.error("Failed to convert message to ArtistSubscriptionMessageApiRequest", e);
throw new IllegalArgumentException("메시지를 받지 못했습니다.");
}
return convertMessage(message, ArtistSubscriptionMessageApiRequest.class);
}

public static GenreSubscriptionMessageApiRequest toGenreSubscriptionMessage(Message message) {
try {
var convertedMessage = objectMapper.readValue(
message.getBody(),
GenreSubscriptionMessageApiRequest.class
);
log.info("Message published successfully to topic: {}",
new String(message.getChannel()));
log.info("Subscribe Message Contents ( GenreSubscriptionMessageServiceRequest : {} )",
message);
return convertMessage(message, GenreSubscriptionMessageApiRequest.class);
}

private static <T> T convertMessage(Message message, Class<T> targetType) {
try {
T convertedMessage = objectMapper.readValue(message.getBody(), targetType);
log.info("Message published successfully to topic: {}", new String(message.getChannel()));
log.info("Subscribe Message Contents ( {} : {} )", targetType.getName(), message);
return convertedMessage;
} catch (IOException e) {
log.error("Failed to convert message to GenreSubscriptionMessageServiceRequest", e);
log.error("Failed to convert message to {}", targetType.getName(), e);
throw new IllegalArgumentException("메시지를 받지 못했습니다.");
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@

@Builder
public record ShowRelationSubscriptionMessageApiRequest(
UUID showId,
List<UUID> artistIds,
List<UUID> genreIds
) {

public SubscriptionMessageServiceRequest toServiceRequest() {
return SubscriptionMessageServiceRequest.builder()
.showId(showId)
.artistIds(artistIds)
.genreIds(genreIds)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.stream.Collectors;
import lombok.RequiredArgsConstructor;
import org.example.SubscriptionMessage;
Expand Down Expand Up @@ -45,7 +46,7 @@ public void showRelationSubscription(SubscriptionMessageServiceRequest request)
MessageParam message = PushMessageTemplate.getSubscribedArtistVisitKoreaAlertMessage(artistName);

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

var genreSubscriptions = genreSubscriptionUseCase.findGenreSubscriptionsByGenreIds(request.genreIds());
Expand All @@ -63,14 +64,15 @@ public void showRelationSubscription(SubscriptionMessageServiceRequest request)
MessageParam message = PushMessageTemplate.getSubscribedGenreVisitKoreaAlertMessage(genreName);

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

@Transactional
public void saveShowAlarm(List<String> fcmTokens, MessageParam message) {
public void saveShowAlarm(UUID showId, List<String> fcmTokens, MessageParam message) {
fcmTokens.stream()
.map(userFcmToken -> ShowAlarm.builder()
.showId(showId)
.userFcmToken(userFcmToken)
.title(message.title())
.content(message.body())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Builder
public record SubscriptionMessageServiceRequest(
UUID showId,
List<UUID> artistIds,
List<UUID> genreIds
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private JobDetail getJobDetail(TicketingAlertServiceResponse ticketingAlert) {
JobDataMap jobDataMap = new JobDataMap();
jobDataMap.put("userFcmToken", ticketingAlert.userFcmToken());
jobDataMap.put("name", ticketingAlert.name());
jobDataMap.put("showId", ticketingAlert.showId());
jobDataMap.put("retryCount", 0);

return JobBuilder.newJob(TicketingAlertQuartzJob.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.example.job;

import java.util.UUID;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.entity.ShowAlarm;
Expand Down Expand Up @@ -35,6 +36,7 @@ public void execute(JobExecutionContext context) {
private void performJobTask(JobExecutionContext context) throws JobExecutionException {
String userFcmToken = context.getMergedJobDataMap().getString("userFcmToken");
String name = context.getMergedJobDataMap().getString("name");
UUID showId = UUID.fromString(context.getMergedJobDataMap().getString("showId"));
String time = context.getTrigger().getKey().getGroup();

MessageParam message = PushMessageTemplate.getTicketingAlertMessageBeforeHours(name, time);
Expand All @@ -47,6 +49,7 @@ private void performJobTask(JobExecutionContext context) throws JobExecutionExce

showAlarmUseCase.save(ShowAlarm.builder()
.userFcmToken(userFcmToken)
.showId(showId)
.title(message.title())
.content(message.body())
.checked(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public record ShowAlarmDomainResponse(
UUID id,
UUID showId,
String title,
String content,
LocalDateTime createAt,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.Table;
import java.util.UUID;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -17,6 +18,9 @@ public class ShowAlarm extends BaseEntity {
@Column(name = "user_fcm_token", nullable = false)
private String userFcmToken;

@Column(name = "show_id", nullable = false)
private UUID showId;

@Column(name = "title", nullable = false)
private String title;

Expand All @@ -27,8 +31,9 @@ public class ShowAlarm extends BaseEntity {
private boolean checked;

@Builder
private ShowAlarm(String userFcmToken, String title, String content, boolean checked) {
private ShowAlarm(String userFcmToken, UUID showId, String title, String content, boolean checked) {
this.userFcmToken = userFcmToken;
this.showId = showId;
this.title = title;
this.content = content;
this.checked = checked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public ShowAlarmPaginationDomainResponse findAllWithCursorPagination(
Projections.constructor(
ShowAlarmDomainResponse.class,
showAlarm.id,
showAlarm.showId,
showAlarm.title,
showAlarm.content,
showAlarm.createdAt,
Expand Down

0 comments on commit b43616f

Please sign in to comment.