-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
10 changed files
with
204 additions
and
90 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
8 changes: 8 additions & 0 deletions
8
...n/java/io/github/depromeet/knockknockbackend/domain/alarm/service/CreateAlarmService.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,8 @@ | ||
package io.github.depromeet.knockknockbackend.domain.alarm.service; | ||
|
||
|
||
import io.github.depromeet.knockknockbackend.domain.alarm.service.dto.CreateAlarmDto; | ||
|
||
public interface CreateAlarmService { | ||
void createAlarm(CreateAlarmDto createAlarmDto); | ||
} |
17 changes: 17 additions & 0 deletions
17
...n/java/io/github/depromeet/knockknockbackend/domain/alarm/service/dto/CreateAlarmDto.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,17 @@ | ||
package io.github.depromeet.knockknockbackend.domain.alarm.service.dto; | ||
|
||
|
||
import io.github.depromeet.knockknockbackend.domain.alarm.domain.types.AlarmType; | ||
import io.github.depromeet.knockknockbackend.domain.user.domain.User; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public class CreateAlarmDto { | ||
private final User sendUser; | ||
private final User receiveUser; | ||
private final String title; | ||
private final String content; | ||
private final AlarmType type; | ||
} |
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
86 changes: 86 additions & 0 deletions
86
...github/depromeet/knockknockbackend/domain/notification/service/NotificationUtilsImpl.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,86 @@ | ||
package io.github.depromeet.knockknockbackend.domain.notification.service; | ||
|
||
|
||
import io.github.depromeet.knockknockbackend.domain.group.domain.Group; | ||
import io.github.depromeet.knockknockbackend.domain.notification.domain.DeviceToken; | ||
import io.github.depromeet.knockknockbackend.domain.notification.domain.NightCondition; | ||
import io.github.depromeet.knockknockbackend.domain.notification.domain.Notification; | ||
import io.github.depromeet.knockknockbackend.domain.notification.domain.repository.NotificationRepository; | ||
import io.github.depromeet.knockknockbackend.domain.notification.exception.NotificationNotFoundException; | ||
import io.github.depromeet.knockknockbackend.domain.user.domain.User; | ||
import io.github.depromeet.knockknockbackend.infrastructor.fcm.FcmService; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@RequiredArgsConstructor | ||
@Component | ||
public class NotificationUtilsImpl implements NotificationUtils { | ||
|
||
private final FcmService fcmService; | ||
private final NotificationRepository notificationRepository; | ||
|
||
@Override | ||
public Notification queryNotificationById(Long notificationId) { | ||
return notificationRepository | ||
.findById(notificationId) | ||
.orElseThrow(() -> NotificationNotFoundException.EXCEPTION); | ||
} | ||
|
||
@Override | ||
public void sendNotification( | ||
Long sendUserId, | ||
Long groupId, | ||
String title, | ||
String content, | ||
String imageUrl, | ||
LocalDateTime reservedAt) { | ||
|
||
List<DeviceToken> deviceTokens = getDeviceTokens(groupId, sendUserId); | ||
List<String> tokens = getFcmTokens(deviceTokens); | ||
|
||
recordNotification( | ||
deviceTokens, | ||
title, | ||
content, | ||
imageUrl, | ||
Group.of(groupId), | ||
User.of(sendUserId), | ||
reservedAt); | ||
|
||
if (tokens.isEmpty()) { | ||
return; | ||
} | ||
fcmService.sendGroupMessage(tokens, title, content, imageUrl); | ||
} | ||
|
||
private List<DeviceToken> getDeviceTokens(Long groupId, Long sendUserId) { | ||
Boolean nightOption = null; | ||
if (NightCondition.isNight()) { | ||
nightOption = true; | ||
} | ||
|
||
return notificationRepository.findTokenByGroupAndOptionAndNonBlock( | ||
sendUserId, groupId, nightOption); | ||
} | ||
|
||
private List<String> getFcmTokens(List<DeviceToken> deviceTokens) { | ||
return deviceTokens.stream().map(DeviceToken::getToken).collect(Collectors.toList()); | ||
} | ||
|
||
private void recordNotification( | ||
List<DeviceToken> deviceTokens, | ||
String title, | ||
String content, | ||
String imageUrl, | ||
Group group, | ||
User sendUser, | ||
LocalDateTime reservedAt) { | ||
Notification notification = | ||
Notification.makeNotificationWithReceivers( | ||
deviceTokens, title, content, imageUrl, group, sendUser, reservedAt); | ||
notificationRepository.save(notification); | ||
} | ||
} |
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
Oops, something went wrong.