Skip to content

Commit

Permalink
Feat : 알람 내역 조회, 알람 내역 엔티티에 targetId 필드 추가
Browse files Browse the repository at this point in the history
- 알람 내역 엔티티에 targetId 필드 추가
- 알람 내역 조회 기능에 targetId 추가
  • Loading branch information
ekzot1212 committed Jul 23, 2024
1 parent b32ef62 commit e30e02c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
5 changes: 4 additions & 1 deletion src/main/java/nbdream/alarm/domain/AlarmHistory.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,15 @@ public class AlarmHistory extends BaseEntity {

private boolean checked;

public AlarmHistory(final Alarm alarm, final AlarmType alarmType, final String title, final String content, final boolean checked) {
private Long targetId;

public AlarmHistory(final Alarm alarm, final AlarmType alarmType, final String title, final String content, final boolean checked, final Long targetId) {
this.alarm = alarm;
this.alarmType = alarmType;
this.title = title;
this.content = content;
this.checked = checked;
this.targetId = targetId;
}

public void alarmCheck() {
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/nbdream/alarm/dto/AlarmHistoryListResDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static AlarmHistoryListResDto from(List<AlarmHistory> alarmHistories) {
alarmHistory.getTitle(),
alarmHistory.getContent(),
alarmHistory.isChecked(),
alarmHistory.getCreatedDate()
alarmHistory.getCreatedDate(),
alarmHistory.getTargetId()
))
.collect(Collectors.toList());

Expand All @@ -47,8 +48,9 @@ class AlarmHistoryResDto {
private boolean checked;
@JsonFormat(pattern = "yyyy-MM-dd HH:mm")
private LocalDateTime createdDate;
private Long targetId;

public AlarmHistoryResDto(Long id, String alarmType, String title, String content, boolean checked, LocalDateTime createdDate) {
public AlarmHistoryResDto(Long id, String alarmType, String title, String content, boolean checked, LocalDateTime createdDate, Long targetId) {
this.id = id;
this.alarmType = alarmType;
this.title = title;
Expand All @@ -57,6 +59,7 @@ public AlarmHistoryResDto(Long id, String alarmType, String title, String conten
this.createdDate = ZonedDateTime.of(createdDate, ZoneId.of("UTC"))
.withZoneSameInstant(ZoneId.of("Asia/Seoul"))
.toLocalDateTime();
this.targetId = targetId;
}

}
2 changes: 1 addition & 1 deletion src/main/java/nbdream/alarm/scheduler/job/FcmJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public void execute(JobExecutionContext jobExecutionContext) {
.build();
try {
fcmService.sendMessageTo(fcmSendDto);
alarmService.saveAlarmHistory(fcmSendDto, alarmSchedule.getAlarm());
alarmService.saveAlarmHistory(fcmSendDto, alarmSchedule.getAlarm(), alarmSchedule.getSchedule().getId());
} catch (Exception e) {
throw new FcmIntenalServerErrorException();
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/nbdream/alarm/service/AlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ public void sendCommentAlarm(Bulletin bulletin, String nickname) {
FcmSendDto fcmSendDto = new FcmSendDto(alarm.getFcmToken(), "농부의 꿈", body, bulletin.getId(), AlarmType.COMMENT);
fcmService.sendMessageTo(fcmSendDto);
//알람 저장
saveAlarmHistory(fcmSendDto, alarm);
saveAlarmHistory(fcmSendDto, alarm, bulletin.getId());
}catch (Exception e){
throw new FcmIntenalServerErrorException();
}
}

public void saveAlarmHistory(FcmSendDto fcmSendDto, Alarm alarm){
AlarmHistory alarmHistory = new AlarmHistory(alarm, fcmSendDto.getAlarmType(), fcmSendDto.getTitle(), fcmSendDto.getBody(), false);
public void saveAlarmHistory(FcmSendDto fcmSendDto, Alarm alarm, Long targetId){
AlarmHistory alarmHistory = new AlarmHistory(alarm, fcmSendDto.getAlarmType(), fcmSendDto.getTitle(), fcmSendDto.getBody(), false, targetId);
alarmHistoryRepository.save(alarmHistory);
}

Expand Down

0 comments on commit e30e02c

Please sign in to comment.