add node to mapping

This commit is contained in:
2024-11-22 21:32:35 +01:00
parent 3efaaf390b
commit 1f8c1c3636
2 changed files with 88 additions and 3 deletions

View File

@@ -1,13 +1,31 @@
package ltd.hlaeja.util
import java.time.ZonedDateTime
import ltd.hlaeja.entity.NodeEntity
import ltd.hlaeja.entity.TypeEntity
import ltd.hlaeja.library.deviceRegistry.Node
import ltd.hlaeja.library.deviceRegistry.Type
import org.springframework.http.HttpStatus.EXPECTATION_FAILED
import org.springframework.web.server.ResponseStatusException
fun Type.Request.toTypeEntity(): TypeEntity = TypeEntity(null, ZonedDateTime.now(), name)
fun TypeEntity.toTypeResponse(): Type.Response {
return Type.Response(id ?: throw ResponseStatusException(EXPECTATION_FAILED), name)
}
fun TypeEntity.toTypeResponse(): Type.Response = Type.Response(
id ?: throw ResponseStatusException(EXPECTATION_FAILED),
name,
)
fun Node.Request.toEntity(): NodeEntity = NodeEntity(
null,
ZonedDateTime.now(),
client,
device,
name,
)
fun NodeEntity.toNodeResponse(): Node.Response = Node.Response(
id ?: throw ResponseStatusException(EXPECTATION_FAILED),
client,
device,
name,
)