Browse Source

Define REST API export and URL naming policy

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.2-alpha
Pekka Helenius 4 years ago
parent
commit
b3c1bb677d
2 changed files with 21 additions and 3 deletions
  1. +11
    -2
      bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java
  2. +10
    -1
      bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java

+ 11
- 2
bookstore/src/main/java/com/fjordtek/bookstore/model/BookRepository.java View File

@ -8,14 +8,21 @@ import java.util.Optional;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
@RepositoryRestResource
@RepositoryRestResource(
path = "booklist",
itemResourceRel = "booklist",
exported = true
)
public interface BookRepository extends CrudRepository<Book, Long> {
@Override
@RestResource(exported = false)
public Optional<Book> findById(Long id);
public List<Book> findByTitle(@Param("title") String title);
@RestResource(path = "title", rel = "title")
public List<Book> findByTitle(@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,
@ -23,8 +30,10 @@ public interface BookRepository extends CrudRepository<Book, Long> {
* we return a single book.
*/
//public List<Book> findByIsbn(String isbn);
@RestResource(exported = false)
public Book findByIsbn(String isbn);
@RestResource(exported = false)
public boolean existsByIsbn(String isbn);
}

+ 10
- 1
bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java View File

@ -5,9 +5,18 @@ package com.fjordtek.bookstore.model;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
@RepositoryRestResource(
path = "categories",
itemResourceRel = "categories",
exported = true
)
public interface CategoryRepository extends CrudRepository<Category, Long> {
public List<Category> findByName(String name);
@RestResource(path = "category", rel = "category")
public List<Category> findByName(@Param("name") String name);
}

Loading…
Cancel
Save