|
7 | 7 | import org.springframework.stereotype.Service; |
8 | 8 | import org.springframework.transaction.annotation.Transactional; |
9 | 9 |
|
10 | | -import in.koreatech.koin.admin.manager.model.Admin; |
11 | 10 | import in.koreatech.koin.admin.manager.repository.AdminRepository; |
12 | 11 | import in.koreatech.koin.admin.notification.dto.AdminNotificationRequest; |
13 | | -import in.koreatech.koin.admin.notification.repository.AdminNotificationRepository; |
14 | 12 | import in.koreatech.koin.admin.notification.repository.AdminNotificationSubscribeRepository; |
15 | 13 | import in.koreatech.koin.domain.notification.model.Notification; |
16 | 14 | import in.koreatech.koin.domain.notification.model.NotificationDetailSubscribeType; |
17 | 15 | import in.koreatech.koin.domain.notification.model.NotificationSubscribe; |
18 | 16 | import in.koreatech.koin.domain.notification.model.NotificationSubscribeType; |
| 17 | +import in.koreatech.koin.domain.notification.service.NotificationService; |
19 | 18 | import in.koreatech.koin.domain.user.model.User; |
20 | 19 | import in.koreatech.koin.global.exception.CustomException; |
21 | | -import in.koreatech.koin.infrastructure.fcm.FcmClient; |
22 | 20 | import lombok.RequiredArgsConstructor; |
23 | | -import lombok.extern.slf4j.Slf4j; |
24 | 21 |
|
25 | | -@Slf4j |
26 | 22 | @Service |
27 | 23 | @RequiredArgsConstructor |
28 | 24 | @Transactional(readOnly = true) |
29 | 25 | public class AdminNotificationService { |
30 | 26 |
|
31 | 27 | private final AdminNotificationSubscribeRepository adminNotificationSubscribeRepository; |
32 | | - private final AdminNotificationRepository adminNotificationRepository; |
33 | 28 | private final AdminRepository adminRepository; |
34 | | - private final FcmClient fcmClient; |
| 29 | + private final NotificationService notificationService; |
35 | 30 |
|
36 | 31 | @Transactional |
37 | 32 | public void sendNotification(AdminNotificationRequest request, Integer adminId) { |
38 | | - Admin admin = adminRepository.getById(adminId); |
| 33 | + adminRepository.getById(adminId); |
39 | 34 | validateDetailTypeMatchesSubscribeType(request.subscribeType(), request.detailSubscribeType()); |
40 | 35 | List<NotificationSubscribe> notificationSubscribes = getNotificationSubscribes( |
41 | 36 | request.subscribeType(), request.detailSubscribeType() |
42 | 37 | ); |
43 | 38 |
|
44 | | - for (NotificationSubscribe notificationSubscribe : notificationSubscribes) { |
45 | | - try { |
| 39 | + List<Notification> notifications = notificationSubscribes.stream() |
| 40 | + .map(notificationSubscribe -> { |
46 | 41 | User user = notificationSubscribe.getUser(); |
47 | | - Notification notification = Notification.of( |
| 42 | + return Notification.of( |
48 | 43 | request.mobileAppPath(), |
49 | 44 | request.schemaUrl(), |
50 | 45 | request.title(), |
51 | 46 | request.message(), |
52 | 47 | request.imageUrl(), |
53 | 48 | user |
54 | 49 | ); |
55 | | - adminNotificationRepository.save(notification); |
56 | | - fcmClient.sendMessage( |
57 | | - user.getDeviceToken(), |
58 | | - notification.getTitle(), |
59 | | - notification.getMessage(), |
60 | | - notification.getImageUrl(), |
61 | | - notification.getMobileAppPath(), |
62 | | - notification.getSchemeUri(), |
63 | | - notification.getType().toLowerCase() |
64 | | - ); |
65 | | - } catch (Exception e) { |
66 | | - log.warn("FCM 알림 전송 과정에서 에러 발생", e); |
67 | | - } |
68 | | - } |
| 50 | + }) |
| 51 | + .toList(); |
| 52 | + |
| 53 | + notificationService.pushNotifications(notifications); |
69 | 54 | } |
70 | 55 |
|
71 | 56 | private void validateDetailTypeMatchesSubscribeType( |
|
0 commit comments