-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDefaultCreateNotificationUseCase.kt
31 lines (24 loc) · 1.15 KB
/
DefaultCreateNotificationUseCase.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
package com.aamdigital.aambackendservice.notification.core
import com.aamdigital.aambackendservice.domain.UseCaseOutcome
import com.aamdigital.aambackendservice.error.AamErrorCode
class DefaultCreateNotificationUseCase(
private val createNotificationHandler: List<CreateNotificationHandler>
) : CreateNotificationUseCase() {
enum class DefaultCreateNotificationUseCaseError : AamErrorCode {
INVALID_NOTIFICATION_CHANNEL_TYPE,
}
override fun apply(request: CreateNotificationRequest): UseCaseOutcome<CreateNotificationData> {
for (handler in createNotificationHandler) {
if (handler.canHandle(request.createUserNotificationEvent.notificationChannelType)) {
val outcome = handler.createMessage(createUserNotificationEvent = request.createUserNotificationEvent)
return UseCaseOutcome.Success(
data = outcome
)
}
}
return UseCaseOutcome.Failure(
errorMessage = "No Handler for this NotificationChannelType",
errorCode = DefaultCreateNotificationUseCaseError.INVALID_NOTIFICATION_CHANNEL_TYPE,
)
}
}