Search in sources :

Example 1 with BookNotFoundException

use of com.tvd12.ezydata.example.jpa.exception.BookNotFoundException in project ezyfox-examples by tvd12.

the class BookService method getBook.

public BookData getBook(Long bookId) {
    Book book = bookRepository.findById(bookId);
    if (book == null) {
        throw new BookNotFoundException("not found book with id: " + bookId);
    }
    final Author author = authorRepository.findById(book.getAuthorId());
    final Category category = categoryRepository.findById(book.getCategoryId());
    return entityToDataConverter.toData(book, author, category);
}
Also used : Category(com.tvd12.ezydata.example.jpa.entity.Category) Book(com.tvd12.ezydata.example.jpa.entity.Book) BookNotFoundException(com.tvd12.ezydata.example.jpa.exception.BookNotFoundException) Author(com.tvd12.ezydata.example.jpa.entity.Author)

Aggregations

Author (com.tvd12.ezydata.example.jpa.entity.Author)1 Book (com.tvd12.ezydata.example.jpa.entity.Book)1 Category (com.tvd12.ezydata.example.jpa.entity.Category)1 BookNotFoundException (com.tvd12.ezydata.example.jpa.exception.BookNotFoundException)1