Skip to content

Commit

Permalink
SKYEDEN-3082 | Add endpoint for tracking urls
Browse files Browse the repository at this point in the history
  • Loading branch information
questras committed Nov 22, 2024
1 parent 5445bb0 commit fbab02d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
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();
}
}
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) {}
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);
}

0 comments on commit fbab02d

Please sign in to comment.