diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java b/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java index 15c4579..0bbccfe 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/BookstoreApplication.java @@ -30,15 +30,28 @@ public class BookstoreApplication extends SpringBootServletInitializer { commonLogger.info("Add new categories to database"); - Category horror = new Category("Horror"); - Category fantasy = new Category("Fantasy"); - categoryRepository.save(horror); - categoryRepository.save(fantasy); + categoryRepository.save(new Category("Horror")); + categoryRepository.save(new Category("Fantasy")); + categoryRepository.save(new Category("Sci-Fi")); commonLogger.info("Add new sample books to database"); - bookRepository.save(new Book("Book 1 title", "Book 1 author", 2020, "1231231-12", 40.00, horror)); - bookRepository.save(new Book("Book 2 title", "Book 2 author", 2005, "3213221-3", 20.17, fantasy)); + bookRepository.save(new Book( + "Bloody Chamber", + "Angela Carter", + 1979, + "1231231-12", + 18.00, + categoryRepository.findByName("Horror").get(0) + )); + bookRepository.save(new Book( + "The Witcher: The Lady of the Lake", + "Andrzej Sapkowski", + 1999, + "3213221-3", + 19.99, + categoryRepository.findByName("Fantasy").get(0) + )); commonLogger.info("------------------------------"); commonLogger.info("Sample categories in the database"); diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java index fbf2364..43699e5 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/CategoryRepository.java @@ -8,7 +8,6 @@ import org.springframework.data.repository.CrudRepository; public interface CategoryRepository extends CrudRepository { - // Handles both INSERT and UPDATE queries - List findById(String name); + List findByName(String name); } \ No newline at end of file