Open spring-projects-issues opened 9 years ago
Oliver Trosien commented
Looking for feedback - is this something useful?
Oliver Drotbohm commented
The question here is how we'd find out whether you'd want that link to appear or not. You can already easily add the link yourself by implementing a ResourceProcessor<Resource<Product>>
in the rating subsystem and manually add the link here using a RepositoryEntityLinks.linkToSearchResource(CustomerRating.class, "findByProduct")
Oliver Trosien commented
Indeed, this is true, a CustomerResourceProcessor can be used to add links, as implemented here:
It should probably use some dependency injection in order to collect all link builders. Even better would be adding an annotation to the finder and letting spring inject the finder links. That's basically the feature request here
Oliver Drotbohm commented
Well, I suggested to autowire a RepositoryEntityLinks
instance above. You can use this to create a link to the search resource and then expand it:
// Identify product
Link productLink = entityLink.linkToSingleResource(Product.class, product.getId());
// Lookup search resource, expand with pointer to product
Map<String, String> parameters = Collections.singletonMap("product", productLink.expand().getHref())
Link link = entityLink.linkToSearchResource(CustomerRating.class, "findByProduct").expand(parameters);
Oliver Trosien opened DATAREST-600 and commented
At the moment structural links of a resource get populated by looking at the properties of an entity. This is fine so far, but Spring Data REST could do better. If you have a repository finder that takes an entity as input, it could actually be rendered as structural link from this entity. Example:
Of course I could add a
@OneToMany
fromProduct
toCustomerRating
, but let's assume this would break modularity of my system. Still it would be nice to have a link on the REST API from a product to its customer ratings. What do you think? Is this a valid use case? Is this possible (e.g. adding annotations to the finder)?Issue Links:
1 votes, 4 watchers