-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNotificationConfiguration.kt
74 lines (67 loc) · 3.42 KB
/
NotificationConfiguration.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package com.aamdigital.aambackendservice.notification.di
import com.aamdigital.aambackendservice.couchdb.core.CouchDbClient
import com.aamdigital.aambackendservice.notification.core.AppCreateNotificationHandler
import com.aamdigital.aambackendservice.notification.core.ApplyNotificationRulesUseCase
import com.aamdigital.aambackendservice.notification.core.CouchDbSyncNotificationConfigUseCase
import com.aamdigital.aambackendservice.notification.core.CreateNotificationHandler
import com.aamdigital.aambackendservice.notification.core.CreateNotificationUseCase
import com.aamdigital.aambackendservice.notification.core.DefaultApplyNotificationRulesUseCase
import com.aamdigital.aambackendservice.notification.core.DefaultCreateNotificationUseCase
import com.aamdigital.aambackendservice.notification.core.PushCreateNotificationHandler
import com.aamdigital.aambackendservice.notification.core.SyncNotificationConfigUseCase
import com.aamdigital.aambackendservice.notification.core.UserNotificationPublisher
import com.aamdigital.aambackendservice.notification.repositiory.NotificationConfigRepository
import com.aamdigital.aambackendservice.notification.repositiory.UserDeviceRepository
import com.google.firebase.messaging.FirebaseMessaging
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
@Configuration
@ConditionalOnProperty(
prefix = "features.notification-api",
name = ["enabled"],
havingValue = "true",
matchIfMissing = false
)
class NotificationConfiguration {
@Bean
fun defaultSyncNotificationConfigUseCase(
couchDbClient: CouchDbClient,
notificationConfigRepository: NotificationConfigRepository,
): SyncNotificationConfigUseCase = CouchDbSyncNotificationConfigUseCase(
couchDbClient = couchDbClient,
notificationConfigRepository = notificationConfigRepository,
)
@Bean
fun defaultApplyNotificationRulesUseCase(
notificationConfigRepository: NotificationConfigRepository,
userNotificationPublisher: UserNotificationPublisher,
): ApplyNotificationRulesUseCase = DefaultApplyNotificationRulesUseCase(
notificationConfigRepository = notificationConfigRepository,
userNotificationPublisher = userNotificationPublisher,
)
@Bean
fun defaultCreateNotificationUseCase(
createNotificationHandler: List<CreateNotificationHandler>
): CreateNotificationUseCase = DefaultCreateNotificationUseCase(
createNotificationHandler = createNotificationHandler,
)
@Bean("push-create-notification-handler")
fun pushCreateNotificationHandler(
firebaseMessaging: FirebaseMessaging,
userDeviceRepository: UserDeviceRepository,
notificationConfigRepository: NotificationConfigRepository,
): CreateNotificationHandler = PushCreateNotificationHandler(
firebaseMessaging = firebaseMessaging,
userDeviceRepository = userDeviceRepository,
notificationConfigRepository = notificationConfigRepository,
)
@Bean("app-create-notification-handler")
fun appCreateNotificationHandler(
couchDbClient: CouchDbClient,
notificationConfigRepository: NotificationConfigRepository,
): CreateNotificationHandler = AppCreateNotificationHandler(
couchDbClient = couchDbClient,
notificationConfigRepository = notificationConfigRepository
)
}