user2793390
user2793390

Reputation: 771

How to get resource link for pagination in katharsis

I'm trying to do pagination. What I have works, but I have some doubts about the way I get a Resource URL.

In my Resource Repository, I inject a ResourceRegistry in a Lazy way (I know it's a circular dependency) to get a URL for my Resource that I then use to generate my links.

  String resourceUrl = resourceRegistry.getResourceUrl(Book.class);

It works fine, but the circular dependency bothers me. Is there some static class to get a resource URL. Or perhaps there's a completely different way of approaching this?

Upvotes: 2

Views: 590

Answers (1)

sorrymissjackson
sorrymissjackson

Reputation: 2715

Maybe this is not a satisfying answer, but katharsis does generate links in it's serializers. You could probably extend one of the katharsis' serializers and make it aware of optional meta information, containing the total number of items available, which the client would need to know anyway. From this data, you could create the top level links for prev and next pages. In the katharsis serializers the resourceRegistry will be available anyway, along with QueryParams, containing the original pagination parameters. This is all very hypothetical though.

The suggested solution by katharsis devs would be:

@JsonApiFindAll
public JsonApiResponse findAll() {
    return new JsonApiResponse()
        .setEntity(Collections.singletonList(new Task(1L, "John")))
        .setLinksInformation(new LinksInformation() {
            public String self = "...";
            public String first = "...";
            public String prev = "...";
            public String next = "...";
            public String last = "...";
        });
}

Taken from here:

Still, hand-crafting the links seems required.

Upvotes: 0

Related Questions