hedera-mirror-node icon indicating copy to clipboard operation
hedera-mirror-node copied to clipboard

Create a generic LinkFactory to return next links for rest java APIs

Open mgoelswirlds opened this issue 1 year ago • 0 comments

Problem

Currently the next link logic is not in a proper service. Also address the issue stated in https://github.com/hashgraph/hedera-mirror-node/pull/7837#discussion_r1546419083

Solution

  • Add a new LinkFactory to create and test general link creation.
  • API specific logic will be in a separate extractor.
public interface LinkFactory {
    <T> Links create(Iterable<T> items, Pageable pageable, ParameterExtractor<T> extractor);

    interface ParameterExtractor<T> {
        Function<T, String> extract(String name);
    }
}

ParameterExtractor<NftAllowance> extractor = param -> switch (param) {
    case "account.id":
        yield NftAllowance::getSpender;
    case "token.id":
        yield NftAllowance::getTokenId;
    default:
        yield null;
};

var links = linkFactory.create(allowances, pageable, extractor);
response.setAllowances(allowances);
response.setLinks(links);

Alternatives

No response

mgoelswirlds avatar Mar 29 '24 02:03 mgoelswirlds