-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SKYEDEN-3082 | Add endpoint for tracking urls
- Loading branch information
Showing
3 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...-management/src/main/java/pl/allegro/tech/hermes/management/api/TrackingUrlsEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package pl.allegro.tech.hermes.management.api; | ||
|
||
import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; | ||
|
||
import jakarta.ws.rs.GET; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.PathParam; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.core.Response; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.stereotype.Controller; | ||
import pl.allegro.tech.hermes.tracker.management.TrackingUrlProvider; | ||
|
||
@Controller | ||
public class TrackingUrlsEndpoint { | ||
private final Optional<TrackingUrlProvider> trackingUrlProvider; | ||
|
||
public TrackingUrlsEndpoint(Optional<TrackingUrlProvider> trackingUrlProvider) { | ||
this.trackingUrlProvider = trackingUrlProvider; | ||
} | ||
|
||
@GET | ||
@Path("/topics/{topic}/tracking-urls") | ||
@Produces(APPLICATION_JSON) | ||
public Response getTopicTrackingUrls(@PathParam("topic") String topic) { | ||
return trackingUrlProvider | ||
.map(provider -> Response.ok(provider.getTrackingUrlsForTopic(topic))) | ||
.orElse(Response.ok(List.of())) | ||
.build(); | ||
} | ||
|
||
@GET | ||
@Path("/topics/{topic}/subscriptions/{subscription}/tracking-urls") | ||
@Produces(APPLICATION_JSON) | ||
public Response getSubscriptionTrackingUrls( | ||
@PathParam("topic") String topic, @PathParam("subscription") String subscription) { | ||
return trackingUrlProvider | ||
.map(provider -> Response.ok(provider.getTrackingUrlsForSubscription(topic, subscription))) | ||
.orElse(Response.ok(List.of())) | ||
.build(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
hermes-tracker/src/main/java/pl/allegro/tech/hermes/tracker/management/TrackingUrl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package pl.allegro.tech.hermes.tracker.management; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
|
||
public record TrackingUrl(@JsonProperty String name, @JsonProperty String url) {} |
10 changes: 10 additions & 0 deletions
10
...-tracker/src/main/java/pl/allegro/tech/hermes/tracker/management/TrackingUrlProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package pl.allegro.tech.hermes.tracker.management; | ||
|
||
import java.util.Collection; | ||
|
||
public interface TrackingUrlProvider { | ||
Collection<TrackingUrl> getTrackingUrlsForTopic(String qualifiedTopicName); | ||
|
||
Collection<TrackingUrl> getTrackingUrlsForSubscription( | ||
String qualifiedTopicName, String subscriptionName); | ||
} |