hedera-mirror-node
hedera-mirror-node copied to clipboard
Create a generic LinkFactory to return next links for rest java APIs
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
LinkFactoryto 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