|
|
@@ -953,4 +953,51 @@ public class OpenAPIHandler {
|
|
|
)).encode())
|
|
|
.onFailure(th -> rc.fail(400, th)));
|
|
|
}
|
|
|
+
|
|
|
+ public void driverIdActionIdUnitsGET(RoutingContext rc) {
|
|
|
+ String host = hostURLFull(rc.request());
|
|
|
+
|
|
|
+ int driverId = Integer.parseInt(rc.pathParam("driverId"));
|
|
|
+ int actionId = Integer.parseInt(rc.pathParam("actionId"));
|
|
|
+
|
|
|
+ List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
|
|
|
+ boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
|
|
|
+
|
|
|
+ repo.findUnitsByDriverIdAndActionId(driverId, actionId)
|
|
|
+ .onSuccess(units -> rc.response().end(new JsonArray(
|
|
|
+ units.stream().map(u -> (navigationLinks ? JsonObject.of(
|
|
|
+ "DriverActionUnit@NavigationLink", String.format("%s/drivers/%d/actions/%d/units/%d",host, driverId, actionId, u.getUnitId())
|
|
|
+ ) : JsonObject.of()).mergeIn(JsonObject.of(
|
|
|
+ "unitId", u.getUnitId(),
|
|
|
+ "name", u.getName(),
|
|
|
+ "description", u.getDescription()
|
|
|
+ ))).collect(toList())
|
|
|
+ ).encode()))
|
|
|
+ .onFailure(th -> rc.fail(400, th));
|
|
|
+ }
|
|
|
+
|
|
|
+ public void driverIdActionIdUnitIdGET(RoutingContext rc) {
|
|
|
+ String host = hostURLFull(rc.request());
|
|
|
+
|
|
|
+ int driverId = Integer.parseInt(rc.pathParam("driverId"));
|
|
|
+ int actionId = Integer.parseInt(rc.pathParam("actionId"));
|
|
|
+ long unitId = Integer.parseInt(rc.pathParam("unitId"));
|
|
|
+
|
|
|
+ List<String> paramNavigationLinks = rc.queryParam("navigationLinks");
|
|
|
+ boolean navigationLinks = paramNavigationLinks.isEmpty() ? DEFAULT_NAVIGATION_LINKS : parseBoolean(paramNavigationLinks.get(0));
|
|
|
+
|
|
|
+ repo.findUnitByIdAndDriverIdAndActionId(unitId, driverId, actionId)
|
|
|
+ .onSuccess(u -> rc.response().end((navigationLinks ? JsonObject.of(
|
|
|
+ "self@NavigationLink", String.format("%s/drivers/%d/actions/%d/units/%d", host, driverId, actionId, u.getUnitId()),
|
|
|
+ "Unit@NavigationLink", String.format("%s/units/%d", host, u.getUnitId()),
|
|
|
+ "DriverAction@NavigationLink", String.format("%s/drivers/%d/actions/%d", host, driverId, actionId),
|
|
|
+ "Events@NavigationLink", String.format("%s/ drivers/%d/units/%d/actions/%d/events", host, driverId, u.getUnitId(), actionId)
|
|
|
+ ) : JsonObject.of()).mergeIn(JsonObject.of(
|
|
|
+ "unitId", u.getUnitId(),
|
|
|
+ "name", u.getName(),
|
|
|
+ "imei", u.getImei(),
|
|
|
+ "description", u.getDescription()
|
|
|
+ )).encode())
|
|
|
+ .onFailure(th -> rc.fail(400, th)));
|
|
|
+ }
|
|
|
}
|