diff --git a/backend/notification/build.gradle b/backend/notification/build.gradle index bc5234663..db8dfd2df 100644 --- a/backend/notification/build.gradle +++ b/backend/notification/build.gradle @@ -30,6 +30,10 @@ dependencies { //s3 implementation 'software.amazon.awssdk:s3:2.21.46' + //flyway + implementation 'org.flywaydb:flyway-core:9.5.1' + implementation 'org.flywaydb:flyway-mysql:9.5.1' + compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/dto/CapsuleSkinNotificationSendDto.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/dto/CapsuleSkinNotificationSendDto.java index 62575c96d..ad188271c 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/dto/CapsuleSkinNotificationSendDto.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/dto/CapsuleSkinNotificationSendDto.java @@ -1,13 +1,13 @@ package site.timecapsulearchive.notification.data.dto; import lombok.Builder; -import site.timecapsulearchive.notification.entity.CapsuleSkinCreationStatus; +import site.timecapsulearchive.notification.entity.NotificationStatus; @Builder public record CapsuleSkinNotificationSendDto( Long memberId, - CapsuleSkinCreationStatus status, + NotificationStatus status, String skinName, String title, String text, diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/mapper/NotificationMapper.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/mapper/NotificationMapper.java index 79a214af7..80f880b89 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/mapper/NotificationMapper.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/mapper/NotificationMapper.java @@ -29,6 +29,7 @@ public Notification capsuleSkinNotificationSendDtoToEntity(CapsuleSkinNotificati .text(dto.text()) .imageUrl(dto.skinUrl()) .notificationCategory(notificationCategory) + .status(dto.status()) .build(); } } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java index 4e857c11e..b7521ee92 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/data/request/CapsuleSkinNotificationSendRequest.java @@ -2,7 +2,7 @@ import jakarta.validation.constraints.NotBlank; import jakarta.validation.constraints.NotNull; -import site.timecapsulearchive.notification.entity.CapsuleSkinCreationStatus; +import site.timecapsulearchive.notification.entity.NotificationStatus; public record CapsuleSkinNotificationSendRequest( @@ -10,7 +10,7 @@ public record CapsuleSkinNotificationSendRequest( Long memberId, @NotNull - CapsuleSkinCreationStatus status, + NotificationStatus status, @NotBlank String skinName, diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/CapsuleSkinCreationStatus.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/CapsuleSkinCreationStatus.java deleted file mode 100644 index 79cf74445..000000000 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/CapsuleSkinCreationStatus.java +++ /dev/null @@ -1,5 +0,0 @@ -package site.timecapsulearchive.notification.entity; - -public enum CapsuleSkinCreationStatus { - SUCCESS_MAKE_CAPSULE_SKIN, FAIL_MAKE_CAPSULE_SKIN -} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/Notification.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/Notification.java index 98d7ff1d2..bd07d8d19 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/Notification.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/Notification.java @@ -2,6 +2,8 @@ import jakarta.persistence.Column; import jakarta.persistence.Entity; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; import jakarta.persistence.FetchType; import jakarta.persistence.GeneratedValue; import jakarta.persistence.GenerationType; @@ -38,13 +40,17 @@ public class Notification extends BaseEntity { @Column(name = "member_id") private Long memberId; + @Column(name = "status") + @Enumerated(EnumType.STRING) + private NotificationStatus status; + @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "notification_category_id", nullable = false) private NotificationCategory notificationCategory; @Builder private Notification(String title, String text, String imageUrl, Long memberId, - NotificationCategory notificationCategory) { + NotificationStatus status, NotificationCategory notificationCategory) { this.title = title; this.text = text; this.imageUrl = imageUrl; diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/NotificationStatus.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/NotificationStatus.java new file mode 100644 index 000000000..520e10da8 --- /dev/null +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/entity/NotificationStatus.java @@ -0,0 +1,5 @@ +package site.timecapsulearchive.notification.entity; + +public enum NotificationStatus { + SUCCESS, FAIL +} diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/exception/MessageNotSendableException.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/exception/MessageNotSendableException.java index 34ab1c549..b5c8f46fa 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/exception/MessageNotSendableException.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/exception/MessageNotSendableException.java @@ -2,7 +2,7 @@ public class MessageNotSendableException extends RuntimeException { - public MessageNotSendableException(Throwable e, String code) { - super(code + "메시지를 보낼 수 없습니다.", e); + public MessageNotSendableException(Throwable e) { + super("메시지를 보낼 수 없습니다.", e); } } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java index d2338e25b..e22317fb0 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/infra/fcm/FCMManager.java @@ -12,7 +12,10 @@ import lombok.RequiredArgsConstructor; import org.springframework.core.io.ClassPathResource; import org.springframework.stereotype.Component; -import site.timecapsulearchive.notification.entity.CapsuleSkinCreationStatus; +import site.timecapsulearchive.notification.data.dto.CapsuleSkinNotificationSendDto; +import site.timecapsulearchive.notification.entity.NotificationStatus; +import site.timecapsulearchive.notification.entity.CategoryName; +import site.timecapsulearchive.notification.entity.Notification; import site.timecapsulearchive.notification.infra.exception.MessageNotSendableException; import site.timecapsulearchive.notification.infra.s3.S3PreSignedUrlManager; @@ -20,7 +23,8 @@ @RequiredArgsConstructor public class FCMManager { - private static final String CAPSULE_SKIN_TOPIC_NAME = "status"; + private static final String TOPIC_DATA_NAME = "topic"; + private static final String STATUS_DATA_NAME = "status"; private static final String TEXT_DATA_NAME = "text"; private static final String TITLE_DATA_NAME = "title"; private static final String IMAGE_DATA_NAME = "imageUrl"; @@ -43,25 +47,24 @@ private InputStream getCredential() throws IOException { } public void send( - String title, - String text, - String skinUrl, - CapsuleSkinCreationStatus status, + CapsuleSkinNotificationSendDto dto, + CategoryName categoryName, String fcmToken ) { try { FirebaseMessaging.getInstance() .send( Message.builder() - .putData(CAPSULE_SKIN_TOPIC_NAME, status.toString()) - .putData(TITLE_DATA_NAME, title) - .putData(TEXT_DATA_NAME, text) - .putData(IMAGE_DATA_NAME, s3PreSignedUrlManager.createS3PreSignedUrlForGet(skinUrl)) + .putData(TOPIC_DATA_NAME, String.valueOf(categoryName)) + .putData(STATUS_DATA_NAME, String.valueOf(dto.status())) + .putData(TITLE_DATA_NAME, dto.title()) + .putData(TEXT_DATA_NAME, dto.text()) + .putData(IMAGE_DATA_NAME, s3PreSignedUrlManager.createS3PreSignedUrlForGet(dto.skinUrl())) .setToken(fcmToken) .build() ); } catch (FirebaseMessagingException e) { - throw new MessageNotSendableException(e, e.getMessagingErrorCode().name()); + throw new MessageNotSendableException(e); } } } diff --git a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/NotificationService.java b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/NotificationService.java index ed0a67ca7..42d2141cd 100644 --- a/backend/notification/src/main/java/site/timecapsulearchive/notification/service/NotificationService.java +++ b/backend/notification/src/main/java/site/timecapsulearchive/notification/service/NotificationService.java @@ -35,7 +35,7 @@ public void sendCapsuleSkinAlarm(CapsuleSkinNotificationSendDto dto) { String fcmToken = memberRepository.findFCMToken(dto.memberId()); if (!fcmToken.isBlank()) { - fcmManager.send(dto.title(), dto.text(), dto.skinUrl(), dto.status(), fcmToken); + fcmManager.send(dto, notificationCategory.getCategoryName(), fcmToken); } } } \ No newline at end of file diff --git a/backend/notification/src/main/resources/config b/backend/notification/src/main/resources/config index 375799a03..9c932cc6c 160000 --- a/backend/notification/src/main/resources/config +++ b/backend/notification/src/main/resources/config @@ -1 +1 @@ -Subproject commit 375799a03e4436f87d1cd69547dd3a69871f2688 +Subproject commit 9c932cc6c99dd13768e8af801d4fbde4d1f6b9bd diff --git a/backend/notification/src/main/resources/db/migration/V1__notification_fix.sql b/backend/notification/src/main/resources/db/migration/V1__notification_fix.sql new file mode 100644 index 000000000..24cdd422b --- /dev/null +++ b/backend/notification/src/main/resources/db/migration/V1__notification_fix.sql @@ -0,0 +1,2 @@ +ALTER TABLE notification + ADD COLUMN status VARCHAR(255); \ No newline at end of file