althaf
11/08/2023, 6:53 AMoverride suspend fun saveToDeviceRegistry(req: SaveToDeviceRegistryReq): Flow<RepositoryState<Unit>> =
flow<RepositoryState<Unit>> {
searchDeviceRegistryByCategoryId(req.deviceProfile.categoryId)?.let {
it.categoryName = req.deviceProfile.categoryName
it.categoryId = req.deviceProfile.categoryId
it.vendor = req.deviceProfile.vendor
it.model = req.deviceProfile.model
it.mac = req.deviceProfile.address
deviceRegistryBox.put(it)
emit(RepositoryState.SuccessState(Unit))
} ?: kotlin.run {
deviceRegistryBox.put(
DeviceRegistryEntity(
categoryName = req.deviceProfile.categoryName,
categoryId = req.deviceProfile.categoryId,
vendor = req.deviceProfile.vendor,
model = req.deviceProfile.model,
mac = req.deviceProfile.address,
)
)
emit(RepositoryState.SuccessState(Unit))
}
}.flowOn(dispatcher)
Is there a better syntax sugar for the above code scenario ?kenkyee
11/08/2023, 3:16 PMalthaf
11/08/2023, 3:43 PM