New endpoints for latest data
This commit is contained in:
@@ -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";
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user