diff --git a/http/node.http b/http/node.http new file mode 100644 index 0000000..38c582b --- /dev/null +++ b/http/node.http @@ -0,0 +1,11 @@ +### +GET {{hostname}}/node-00000000-0000-7000-0000-000000000001 + + +### add measurement for one +PUT {{hostname}}/node-00000000-0000-7000-0000-000000000001 +Content-Type: application/json + +{ + "configuration": "test" +} diff --git a/src/main/kotlin/ltd/hlaeja/controller/NodeController.kt b/src/main/kotlin/ltd/hlaeja/controller/NodeController.kt new file mode 100644 index 0000000..ccaefb8 --- /dev/null +++ b/src/main/kotlin/ltd/hlaeja/controller/NodeController.kt @@ -0,0 +1,37 @@ +package ltd.hlaeja.controller + +import java.util.UUID +import ltd.hlaeja.library.deviceConfiguration.Node +import ltd.hlaeja.service.NodeService +import ltd.hlaeja.util.toEntity +import ltd.hlaeja.util.toResponse +import mu.KotlinLogging +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PutMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.RestController +import reactor.core.publisher.Mono + +private val log = KotlinLogging.logger {} + +@RestController +class NodeController( + private val service: NodeService, +) { + + @GetMapping("/node-{node}") + fun getNodeConfiguration( + @PathVariable node: UUID, + ): Mono = service.getConfiguration(node) + .map { it.toResponse() } + .also { log.debug("Endpoint getNodeConfiguration for node: {}", node) } + + @PutMapping("/node-{node}") + fun updateNodeConfiguration( + @PathVariable node: UUID, + @RequestBody nodeRequest: Node.Request, + ): Mono = service.updateDevice(nodeRequest.toEntity(node)) + .map { it.toResponse() } + .also { log.debug("Endpoint updateNodeConfiguration for node: {}", node) } +}