-
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.
- 알림 전체 발송 API를 구현했어요.
- Loading branch information
Showing
3 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
31 changes: 31 additions & 0 deletions
31
...java/com/bamdoliro/sinabro/application/notification/SendNotificationToAllUserUseCase.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,31 @@ | ||
package com.bamdoliro.sinabro.application.notification; | ||
|
||
import com.bamdoliro.sinabro.domain.fcm.token.service.FCMTokenFacade; | ||
import com.bamdoliro.sinabro.domain.notification.domain.Notification; | ||
import com.bamdoliro.sinabro.domain.user.domain.User; | ||
import com.bamdoliro.sinabro.infrastructure.fcm.FCMService; | ||
import com.bamdoliro.sinabro.infrastructure.persistence.fcm.token.FCMTokenRepository; | ||
import com.bamdoliro.sinabro.infrastructure.persistence.notification.NotificationRepository; | ||
import com.bamdoliro.sinabro.infrastructure.persistence.user.UserRepository; | ||
import com.bamdoliro.sinabro.presentation.notification.dto.request.SendNotificationRequest; | ||
import com.bamdoliro.sinabro.shared.annotation.UseCase; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@RequiredArgsConstructor | ||
@UseCase | ||
public class SendNotificationToAllUserUseCase { | ||
|
||
private final FCMService fcmService; | ||
private final NotificationRepository notificationRepository; | ||
private final FCMTokenRepository fcmTokenRepository; | ||
|
||
@Transactional | ||
public void execute(SendNotificationRequest request) { | ||
fcmTokenRepository.findAll() | ||
.forEach(fcmToken -> { | ||
fcmService.sendMessageTo(fcmToken.getToken(), request.getTitle(), request.getBody()); | ||
notificationRepository.save(new Notification(request.getTitle(), request.getBody(), fcmToken.getUser())); | ||
}); | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
.../com/bamdoliro/sinabro/presentation/notification/dto/request/SendNotificationRequest.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 |
---|---|---|
@@ -1,14 +1,17 @@ | ||
package com.bamdoliro.sinabro.presentation.notification.dto.request; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
import lombok.*; | ||
|
||
@Getter | ||
@ToString | ||
@AllArgsConstructor | ||
public class SendNotificationRequest { | ||
|
||
@NotBlank(message = "필수값입니다.") | ||
private String title; | ||
|
||
@NotBlank(message = "필수값입니다.") | ||
private String body; | ||
} | ||
|