diff --git a/http/measurement.http b/http/measurement.http new file mode 100644 index 0000000..16dc644 --- /dev/null +++ b/http/measurement.http @@ -0,0 +1,32 @@ +### add measurement for all +POST {{hostname}}/client-00000000-0000-7000-0001-000000000001 +Content-Type: application/json + +{ + "tags": { + "device": "00000000-0000-7000-0002-000000000001", + "node": "00000000-0000-7000-0003-000000000001" + }, + "fields": { + "button0": 1, + "button1": 0, + "button2": 1 + } +} + +### add measurement for one +POST {{hostname}}/client-00000000-0000-7000-0001-000000000001 +Content-Type: application/json + +{ + "tags": { + "device": "00000000-0000-7000-0002-000000000001", + "node": "00000000-0000-7000-0003-000000000001" + }, + "fields": { + "button1": 0 + } +} + +### add measurement +GET {{hostname}}/client-00000000-0000-7000-0001-000000000001/node-00000000-0000-7000-0003-000000000001 diff --git a/src/main/kotlin/ltd/hlaeja/controller/MeasurementController.kt b/src/main/kotlin/ltd/hlaeja/controller/MeasurementController.kt new file mode 100644 index 0000000..da5e2a2 --- /dev/null +++ b/src/main/kotlin/ltd/hlaeja/controller/MeasurementController.kt @@ -0,0 +1,31 @@ +package ltd.hlaeja.controller + +import java.util.UUID +import ltd.hlaeja.library.deviceData.MeasurementData +import ltd.hlaeja.service.MeasurementService +import org.springframework.http.HttpStatus.CREATED +import org.springframework.web.bind.annotation.GetMapping +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.PostMapping +import org.springframework.web.bind.annotation.RequestBody +import org.springframework.web.bind.annotation.ResponseStatus +import org.springframework.web.bind.annotation.RestController + +@RestController +class MeasurementController( + private val service: MeasurementService, +) { + + @PostMapping("/client-{client}") + @ResponseStatus(CREATED) + suspend fun addMeasurement( + @PathVariable client: UUID, + @RequestBody measurement: MeasurementData.Request, + ) = service.addMeasurement(client, measurement) + + @GetMapping("/client-{client}/node-{node}") + suspend fun getLastDeviceMeasurement( + @PathVariable client: UUID, + @PathVariable node: UUID, + ): MeasurementData.Response = service.getNodeMeasurement(client, node) +}