add device type
add postEditType to TypeController update form.html and messages.html for saving types add updateType in DeviceRegistryService add WebClient deviceRegistryTypesUpdate in DeviceRegisterWebClientCalls.kt add getEditType to TypeController update type form.html for edit device type add Type Response toTypeForm in Mapping.kt add getType to DeviceRegistryService add WebClient deviceRegistryType in DeviceRegisterWebClientCalls.kt update edit link in device type list.html add getCreateType and postCreateType to TypeController add device type form.html add TypeFormadd TypeForm toTypeRequest in Mapping.kt add TypeForm add createType to DeviceRegistryService add deviceRegistryTypesCreate in DeviceRegisterWebClientCalls.kt add TypeNameDuplicateException add DeviceRegistryException extract validationErrors from postCreateAccount in AccountController to util Controller update AccountController getAccounts and TypeController getTypes with max show value add redis for spring boot session - make RemoteUserDetail Serializable - add application properties - add dependencies add TypeController add list.html for type extract fragment pagination.html from users.html add DeviceRegistryService with getTypes add DeviceRegisterWebClientCalls.kt with deviceRegistryTypes set up hlaeja device registry add type to layout menu add type to admin SecurityConfiguration
This commit is contained in:
63
src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt
Normal file
63
src/main/kotlin/ltd/hlaeja/service/DeviceRegistryService.kt
Normal file
@@ -0,0 +1,63 @@
|
||||
package ltd.hlaeja.service
|
||||
|
||||
import java.util.UUID
|
||||
import ltd.hlaeja.exception.DeviceRegistryException
|
||||
import ltd.hlaeja.exception.HlaejaException
|
||||
import ltd.hlaeja.library.deviceRegistry.Type
|
||||
import ltd.hlaeja.library.deviceRegistry.Types
|
||||
import ltd.hlaeja.property.DeviceRegistryProperty
|
||||
import ltd.hlaeja.util.deviceRegistryType
|
||||
import ltd.hlaeja.util.deviceRegistryTypes
|
||||
import ltd.hlaeja.util.deviceRegistryTypesCreate
|
||||
import ltd.hlaeja.util.deviceRegistryTypesUpdate
|
||||
import org.springframework.http.HttpStatus.BAD_REQUEST
|
||||
import org.springframework.stereotype.Service
|
||||
import org.springframework.web.reactive.function.client.WebClient
|
||||
import org.springframework.web.server.ResponseStatusException
|
||||
import reactor.core.publisher.Flux
|
||||
import reactor.core.publisher.Mono
|
||||
|
||||
@Service
|
||||
class DeviceRegistryService(
|
||||
private val webClient: WebClient,
|
||||
private val property: DeviceRegistryProperty,
|
||||
) {
|
||||
|
||||
fun getTypes(
|
||||
page: Int,
|
||||
show: Int,
|
||||
): Flux<Types.Response> = webClient.deviceRegistryTypes(page, show, property)
|
||||
|
||||
fun createType(
|
||||
request: Type.Request,
|
||||
): Mono<Type.Response> = webClient.deviceRegistryTypesCreate(request, property)
|
||||
.onErrorResume { error ->
|
||||
when (error) {
|
||||
is DeviceRegistryException -> Mono.error(error)
|
||||
else -> Mono.error(ResponseStatusException(BAD_REQUEST, error.message))
|
||||
}
|
||||
}
|
||||
|
||||
fun getType(
|
||||
type: UUID,
|
||||
): Mono<Type.Response> = webClient.deviceRegistryType(type, property)
|
||||
.onErrorResume { error ->
|
||||
when (error) {
|
||||
is ResponseStatusException -> Mono.error(error)
|
||||
else -> Mono.error(ResponseStatusException(BAD_REQUEST, error.message))
|
||||
}
|
||||
}
|
||||
|
||||
fun updateType(
|
||||
type: UUID,
|
||||
request: Type.Request,
|
||||
): Mono<Type.Response> = webClient.deviceRegistryTypesUpdate(type, request, property)
|
||||
.onErrorResume(::errorHandler)
|
||||
|
||||
private fun errorHandler(
|
||||
error: Throwable,
|
||||
): Mono<out Type.Response> = when (error) {
|
||||
is HlaejaException -> Mono.error(error)
|
||||
else -> Mono.error(ResponseStatusException(BAD_REQUEST, error.message))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user