Skip to content

Commit

Permalink
create a method to search routes and listeners by parameter "q"
Browse files Browse the repository at this point in the history
  • Loading branch information
steniobhz committed Sep 30, 2024
1 parent a0c2495 commit ae01c87
Showing 1 changed file with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,14 @@ public boolean handle(final RoutingContext ctx) {
}
}

HttpServerResponse response = ctx.response();
String queryParam = request.getParam("q");

if ((queryParam != null) && !queryParam.isEmpty()) {
this.handleHookSearch(queryParam,response);
return true;
}

/*
* 2) Check if we have to queue a request for listeners
*/
Expand All @@ -592,6 +600,39 @@ public boolean handle(final RoutingContext ctx) {
}
}

/**
* Handles hook search requests based on the 'destination' property.
* Searches in both routes and listeners.
*
* @param queryParam the RoutingContext of the request
*/
public void handleHookSearch(String queryParam,HttpServerResponse response) {
JsonObject result = new JsonObject();
JsonArray matchingRoutes = new JsonArray();
JsonArray matchingListeners = new JsonArray();

// Search routes by destination
routeRepository.getRoutes().forEach((routeKey, route) -> {
if (route.getHook().getDestination().contains(queryParam)) {
matchingRoutes.add(routeKey);
}
});

// Search listeners by destination
listenerRepository.getListeners().forEach(listener -> {
if (listener.getHook().getDestination().contains(queryParam)) {
matchingListeners.add(listener.getListenerId());
}
});

// Build and send the response
result.put("routes", matchingRoutes);
result.put("listeners", matchingListeners);

response.putHeader("content-type", "application/json").end(result.encode());
}


/**
* Create a listing of routes in the given parent. This happens
* only if we have a GET request, the routes are listable and
Expand Down

0 comments on commit ae01c87

Please sign in to comment.