Add device registry
- add RegistryController - add DeviceRegistryService - add Helper.kt - add device registry property - set up registry property
This commit is contained in:
24
src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt
Normal file
24
src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package ltd.hlaeja.service
|
||||
|
||||
import ltd.hlaeja.library.deviceRegistry.Device
|
||||
import ltd.hlaeja.util.logCall
|
||||
import ltd.hlaeja.property.DeviceRegistryProperty
|
||||
import org.springframework.http.HttpStatus.REQUEST_TIMEOUT
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import org.springframework.web.reactive.function.client.awaitBodyOrNull
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
|
||||
@Service
|
||||
class DeviceRegistryService(
|
||||
private val webClient: WebClient,
|
||||
private val deviceRegistryProperty: DeviceRegistryProperty,
|
||||
) {
|
||||
suspend fun registerDevice(
|
||||
request: Device.Request,
|
||||
): Device.Response = webClient.post()
|
||||
.uri("${deviceRegistryProperty.url}/device".also(::logCall))
|
||||
.bodyValue(request)
|
||||
.retrieve()
|
||||
.awaitBodyOrNull<Device.Response>() ?: throw ResponseStatusException(REQUEST_TIMEOUT)
|
||||
}
|
||||
Reference in New Issue
Block a user