I have a controller that looks something like this:
@RepositoryRestController
public class PersonOmnisearchController {
@Autowired
private PersonRepository personRepository;
@ResponseBody
@RequestMapping(value = "/persons/search/personOmnisearch", method = RequestMethod.GET)
public ResponseEntity<?> personOmnisearch(@RequestParam("search") String search, PersistentEntityResourceAssembler assembler) {
Person p = personRepository.findOne(Long.valueOf(search));
if (p == null) {
p = personRepository.findBySsn(search);
}
if (p == null) {
throw new ResourceNotFoundException();
}
return ResponseEntity.ok(assembler.toResource(p));
}
}
It works great, but when using Traverson to fetch the data, there is no personOmnisearch
link in the /api/persons/search
's _links
section. How do I let Spring Data REST know about my controller to put it in the api so it can be navigated to without having to know the direct URL?
Here's my Traverson code in case it helps:
api.json()
.follow('$._links.persons.href', '$._links.search.href', 'omniSearch')
.withTemplateParameters({
search: search
})
.getResource()
P.S. - I'm not sure if this is a Spring Data REST or HATEOAS question, so I tagged both. Feel free to remove whichever one is irrelevant.