From 36dced09fe6ae6c388fd7c7dfb1c7c62915b3176 Mon Sep 17 00:00:00 2001 From: nohy6630 Date: Sat, 22 Jun 2024 19:26:52 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=95=8C=EB=A6=BC=20=EC=9C=A0=ED=98=95?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../alarmserver/domain/alarm/entity/Alarm.java | 12 ++++++++++-- .../alarmserver/domain/alarm/entity/AlarmType.java | 5 +++++ .../domain/alarm/service/SendAlarmService.java | 3 +++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/AlarmType.java diff --git a/src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/Alarm.java b/src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/Alarm.java index 8a31a35..5b4cc2f 100644 --- a/src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/Alarm.java +++ b/src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/Alarm.java @@ -23,6 +23,8 @@ public class Alarm { @ElementCollection private List recipients; + // 알림 유형이 EMAIL일 경우 수신자 이메일 주소 + // 알림 유형이 FCM일 경우 수신자 FCM 토큰 @Comment("제목") private String subject; @@ -37,9 +39,14 @@ public class Alarm { @Enumerated(EnumType.STRING) private AlarmStatus status; - public static Alarm ofImmediate(List recipients, String subject, String content) { + @Comment("알림 유형") + @Enumerated(EnumType.STRING) + private AlarmType type; + + public static Alarm ofImmediate(AlarmType type, List recipients, String subject, String content) { LocalDateTime now = ZonedDateTime.now(ZoneId.of("Asia/Seoul")).toLocalDateTime(); return Alarm.builder() + .type(type) .recipients(recipients) .subject(subject) .content(content) @@ -48,8 +55,9 @@ public static Alarm ofImmediate(List recipients, String subject, String .build(); } - public static Alarm ofScheduled(List recipients, String subject, String content, LocalDateTime sendTime) { + public static Alarm ofScheduled(AlarmType type, List recipients, String subject, String content, LocalDateTime sendTime) { return Alarm.builder() + .type(type) .recipients(recipients) .subject(subject) .content(content) diff --git a/src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/AlarmType.java b/src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/AlarmType.java new file mode 100644 index 0000000..a5ec3f0 --- /dev/null +++ b/src/main/java/com/yeongjin/alarmserver/domain/alarm/entity/AlarmType.java @@ -0,0 +1,5 @@ +package com.yeongjin.alarmserver.domain.alarm.entity; + +public enum AlarmType { + EMAIL, FCM +} diff --git a/src/main/java/com/yeongjin/alarmserver/domain/alarm/service/SendAlarmService.java b/src/main/java/com/yeongjin/alarmserver/domain/alarm/service/SendAlarmService.java index 3734c78..dfd033b 100644 --- a/src/main/java/com/yeongjin/alarmserver/domain/alarm/service/SendAlarmService.java +++ b/src/main/java/com/yeongjin/alarmserver/domain/alarm/service/SendAlarmService.java @@ -3,6 +3,7 @@ import com.yeongjin.alarmserver.domain.alarm.dto.request.SendImmediateAlarmReq; import com.yeongjin.alarmserver.domain.alarm.dto.request.SendScheduledAlarmReq; import com.yeongjin.alarmserver.domain.alarm.entity.Alarm; +import com.yeongjin.alarmserver.domain.alarm.entity.AlarmType; import com.yeongjin.alarmserver.domain.alarm.repository.AlarmRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -20,6 +21,7 @@ public class SendAlarmService { public Long sendImmediateEmail(SendImmediateAlarmReq sendImmediateAlarmReq) { Alarm alarm = alarmRepository.save( Alarm.ofImmediate( + AlarmType.EMAIL, sendImmediateAlarmReq.getRecipients(), sendImmediateAlarmReq.getSubject(), sendImmediateAlarmReq.getContent() @@ -33,6 +35,7 @@ public Long sendImmediateEmail(SendImmediateAlarmReq sendImmediateAlarmReq) { public Long sendScheduledEmail(SendScheduledAlarmReq sendScheduledAlarmReq) { Alarm alarm = alarmRepository.save( Alarm.ofScheduled( + AlarmType.EMAIL, sendScheduledAlarmReq.getRecipients(), sendScheduledAlarmReq.getSubject(), sendScheduledAlarmReq.getContent(),