Skip to content

Commit

Permalink
feat: 알림 유형 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
nohy6630 committed Jun 22, 2024
1 parent 9cbe078 commit 36dced0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class Alarm {

@ElementCollection
private List<String> recipients;
// 알림 유형이 EMAIL일 경우 수신자 이메일 주소
// 알림 유형이 FCM일 경우 수신자 FCM 토큰

@Comment("제목")
private String subject;
Expand All @@ -37,9 +39,14 @@ public class Alarm {
@Enumerated(EnumType.STRING)
private AlarmStatus status;

public static Alarm ofImmediate(List<String> recipients, String subject, String content) {
@Comment("알림 유형")
@Enumerated(EnumType.STRING)
private AlarmType type;

public static Alarm ofImmediate(AlarmType type, List<String> 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)
Expand All @@ -48,8 +55,9 @@ public static Alarm ofImmediate(List<String> recipients, String subject, String
.build();
}

public static Alarm ofScheduled(List<String> recipients, String subject, String content, LocalDateTime sendTime) {
public static Alarm ofScheduled(AlarmType type, List<String> recipients, String subject, String content, LocalDateTime sendTime) {
return Alarm.builder()
.type(type)
.recipients(recipients)
.subject(subject)
.content(content)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.yeongjin.alarmserver.domain.alarm.entity;

public enum AlarmType {
EMAIL, FCM
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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(),
Expand Down

0 comments on commit 36dced0

Please sign in to comment.