Skip to content

Commit

Permalink
Merge pull request #255 from tukcomCD2024/develop_back_notification
Browse files Browse the repository at this point in the history
develop back notification to develop back 머지
  • Loading branch information
GaBaljaintheroom authored Mar 14, 2024
2 parents d8e9f5e + 2bf3022 commit 624f154
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 25 deletions.
4 changes: 4 additions & 0 deletions backend/notification/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public Notification capsuleSkinNotificationSendDtoToEntity(CapsuleSkinNotificati
.text(dto.text())
.imageUrl(dto.skinUrl())
.notificationCategory(notificationCategory)
.status(dto.status())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

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(

@NotNull
Long memberId,

@NotNull
CapsuleSkinCreationStatus status,
NotificationStatus status,

@NotBlank
String skinName,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package site.timecapsulearchive.notification.entity;

public enum NotificationStatus {
SUCCESS, FAIL
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class MessageNotSendableException extends RuntimeException {

public MessageNotSendableException(Throwable e, String code) {
super(code + "메시지를 보낼 수 없습니다.", e);
public MessageNotSendableException(Throwable e) {
super("메시지를 보낼 수 없습니다.", e);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
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;

@Component
@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";
Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion backend/notification/src/main/resources/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE notification
ADD COLUMN status VARCHAR(255);

0 comments on commit 624f154

Please sign in to comment.