feat: add isolated activity event writer
This commit is contained in:
+45
@@ -0,0 +1,45 @@
|
|||||||
|
package com.flagship.abox.manager.automation.activity
|
||||||
|
|
||||||
|
import com.flagship.abox.manager.domain.ActivityEvent
|
||||||
|
import com.flagship.abox.manager.domain.ActivityEventId
|
||||||
|
import com.flagship.abox.manager.domain.ActivityEventKind
|
||||||
|
import com.flagship.abox.manager.domain.ActivityOutcome
|
||||||
|
import com.flagship.abox.manager.domain.ActivityRepository
|
||||||
|
import com.flagship.abox.manager.domain.ActivitySource
|
||||||
|
import com.flagship.abox.manager.domain.ActivityTarget
|
||||||
|
import com.flagship.abox.manager.domain.ActivityTargetType
|
||||||
|
import com.flagship.abox.manager.domain.DeviceName
|
||||||
|
import com.flagship.abox.manager.domain.ProviderProfileId
|
||||||
|
import java.util.UUID
|
||||||
|
import kotlinx.coroutines.CoroutineScope
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class ActivityEventWriter(
|
||||||
|
private val repository: ActivityRepository,
|
||||||
|
private val scope: CoroutineScope,
|
||||||
|
) {
|
||||||
|
fun recordDevice(
|
||||||
|
profileId: ProviderProfileId,
|
||||||
|
deviceName: DeviceName,
|
||||||
|
kind: ActivityEventKind,
|
||||||
|
outcome: ActivityOutcome,
|
||||||
|
errorCode: String? = null,
|
||||||
|
) {
|
||||||
|
scope.launch {
|
||||||
|
runCatching {
|
||||||
|
repository.append(
|
||||||
|
ActivityEvent(
|
||||||
|
id = ActivityEventId(UUID.randomUUID().toString()),
|
||||||
|
profileId = profileId,
|
||||||
|
occurredAtEpochMillis = System.currentTimeMillis(),
|
||||||
|
kind = kind,
|
||||||
|
source = ActivitySource.USER,
|
||||||
|
outcome = outcome,
|
||||||
|
target = ActivityTarget(ActivityTargetType.DEVICE, deviceName.value, deviceName.value),
|
||||||
|
errorCode = errorCode,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user