1
0

New endpoints for latest data

This commit is contained in:
Jose
2025-03-11 20:39:00 +01:00
parent a4de23e7ef
commit 1a0848805b
3 changed files with 50 additions and 3 deletions

View File

@@ -27,6 +27,8 @@ public class Constants {
public static final String GET_DEVICE_SENSORS = API_PREFIX + "/devices/:deviceId/sensors";
public static final String POST_DEVICES = API_PREFIX + "/devices";
public static final String PUT_DEVICE_BY_ID = API_PREFIX + "/devices/:deviceId";
public static final String GET_DEVICE_ACTUATORS = API_PREFIX + "/devices/:deviceId/actuators";
public static final String GET_DEVICE_LATEST_VALUES = API_PREFIX + "/devices/:deviceId/latest";
public static final String GET_SENSORS = API_PREFIX + "/sensors";
public static final String GET_SENSOR_BY_ID = API_PREFIX + "/sensors/:sensorId";

View File

@@ -46,6 +46,8 @@ public class ApiVerticle extends AbstractVerticle {
router.route(HttpMethod.GET, Constants.GET_DEVICES).handler(this::getDevicesHandler);
router.route(HttpMethod.GET, Constants.GET_DEVICE_BY_ID).handler(this::getDeviceByIdHandler);
router.route(HttpMethod.GET, Constants.GET_DEVICE_SENSORS).handler(this::getDeviceSensorsHandler);
router.route(HttpMethod.GET, Constants.GET_DEVICE_ACTUATORS).handler(this::getDeviceActuatorsHandler);
router.route(HttpMethod.GET, Constants.GET_DEVICE_LATEST_VALUES).handler(this::getDeviceLatestValuesHandler);
router.route(HttpMethod.POST, Constants.POST_DEVICES).handler(this::postDeviceHandler);
router.route(HttpMethod.PUT, Constants.PUT_DEVICE_BY_ID).handler(this::putDeviceByIdHandler);
@@ -182,6 +184,26 @@ public class ApiVerticle extends AbstractVerticle {
.build();
sendQuery(query, context);
}
private void getDeviceActuatorsHandler(RoutingContext context) {
String deviceId = context.request().getParam("deviceId");
String query = QueryBuilder
.select("*")
.from("actuators")
.where("deviceId = ?", deviceId)
.build();
sendQuery(query, context);
}
private void getDeviceLatestValuesHandler(RoutingContext context) {
String deviceId = context.request().getParam("deviceId");
String query = QueryBuilder
.select("*")
.from("v_latest_values")
.where("deviceId = ?", deviceId)
.build();
sendQuery(query, context);
}
private void postDeviceHandler(RoutingContext context) {
JsonObject body = context.body().asJsonObject();