From cccbaf56e5274160cb4cb2561b279ef79014aa0f Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Wed, 30 Sep 2020 12:17:11 +0300 Subject: [PATCH] REST API: improve searching scheme Signed-off-by: Pekka Helenius --- .../fjordtek/bookstore/model/AuthorRepository.java | 12 +++++++++++- .../com/fjordtek/bookstore/model/BookRepository.java | 2 +- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java index 17a3af8..576843b 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/AuthorRepository.java @@ -23,9 +23,19 @@ import org.springframework.data.rest.core.annotation.RestResource; ) public interface AuthorRepository extends CrudRepository { - @RestResource(path = "author", rel = "author") + @RestResource(path = "fullname", rel = "fullname") public List findByFirstNameIgnoreCaseContainingAndLastNameIgnoreCaseContaining( @Param("firstname") String firstName, @Param("lastname") String lastName ); + @RestResource(path = "firstname", rel = "firstname") + public List findByFirstNameIgnoreCaseContaining( + @Param("firstname") String firstName + ); + + @RestResource(path = "lastname", rel = "lastname") + public List findByLastNameIgnoreCaseContaining( + @Param("lastname") String lastName + ); + } \ No newline at end of file diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java index f93df03..eb8f2cc 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java @@ -31,7 +31,7 @@ public interface BookRepository extends CrudRepository { public Optional findById(Long id); @RestResource(path = "title", rel = "title") - public List findByTitle(@Param("name") String title); + public List findByTitleIgnoreCaseContaining(@Param("name") String title); /* Assume a single book with a single ISBN, or multiple books with possibly duplicate ISBNs? * For meanwhile, we have a UNIQUE constraint for ISBN values. If this policy changes,