-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
113 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
src/main/java/com/yeongjin/alarmserver/domain/alarm/repository/AlarmRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.yeongjin.alarmserver.domain.alarm.repository; | ||
|
||
import com.yeongjin.alarmserver.domain.alarm.entity.Alarm; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public interface AlarmRepository extends JpaRepository<Alarm, Long> { | ||
@Query("select e.id from Alarm e where e.isSent = true") | ||
List<Long> findIdsIsSent(); | ||
|
||
@Query("select e from Alarm e where e.sendTime <= :sendTime and e.isSent = false") | ||
List<Alarm> findEmailsToSend(LocalDateTime sendTime); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/main/java/com/yeongjin/alarmserver/domain/alarm/service/SendAlarmService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.yeongjin.alarmserver.domain.alarm.service; | ||
|
||
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.repository.AlarmRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.mail.javamail.JavaMailSender; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional(readOnly = true) | ||
@Slf4j | ||
public class SendAlarmService { | ||
private final AlarmRepository alarmRepository; | ||
private final SendAlarmPublisher sendEmailPublisher; | ||
private final SendAlarmSubscriber sendAlarmSubscriber; | ||
private final JavaMailSender javaMailSender; | ||
|
||
@Transactional | ||
public Long sendImmediateEmail(SendImmediateAlarmReq sendImmediateAlarmReq) { | ||
Alarm alarm = alarmRepository.save( | ||
Alarm.ofImmediate( | ||
sendImmediateAlarmReq.getRecipients(), | ||
sendImmediateAlarmReq.getSubject(), | ||
sendImmediateAlarmReq.getContent() | ||
) | ||
); | ||
alarm.setSent(); | ||
sendEmailPublisher.publishToRedis(alarm); | ||
return alarm.getId(); | ||
} | ||
|
||
@Transactional | ||
public Long sendScheduledEmail(SendScheduledAlarmReq sendScheduledAlarmReq) { | ||
Alarm alarm = alarmRepository.save( | ||
Alarm.ofScheduled( | ||
sendScheduledAlarmReq.getRecipients(), | ||
sendScheduledAlarmReq.getSubject(), | ||
sendScheduledAlarmReq.getContent(), | ||
sendScheduledAlarmReq.getSendTime().withSecond(0) | ||
) | ||
); | ||
return alarm.getId(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 0 additions & 51 deletions
51
src/main/java/com/yeongjin/alarmserver/domain/api/service/EmailAlarmService.java
This file was deleted.
Oops, something went wrong.
16 changes: 0 additions & 16 deletions
16
src/main/java/com/yeongjin/alarmserver/domain/repository/EmailAlarmRepository.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters