Package com.example.restapi.service
Class BookService
java.lang.Object
com.example.restapi.service.BookService
Service class that provides business logic for managing
Book and borrowing operations.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate BookRepositoryRepository for managingBookentities.private UserRepository -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanborrowBook(Long bookId, Long userId) createBook(Book book) Creates a new book entry in the repository.voiddeleteBook(Long id) Deletes the Book identified by id.Retrieves all books from the repository.getBookById(Long id) Retrieves a book by its unique identifier.booleanreturnBook(Long bookId) Returns a borrowed book, making it available for others.updateBook(Long id, Book bookDetails) Updates an existing book's details.
-
Field Details
-
bookRepository
Repository for managingBookentities. -
userRepository
-
-
Constructor Details
-
BookService
public BookService()
-
-
Method Details
-
getAllBooks
Retrieves all books from the repository.- Returns:
- a list of all
Bookobjects
-
getBookById
Retrieves a book by its unique identifier. -
createBook
Creates a new book entry in the repository. -
updateBook
Updates an existing book's details. -
deleteBook
Deletes the Book identified by id. deleteBook() needs to be public because it is used by clients who wish to remove books identified by id -
borrowBook
-
returnBook
Returns a borrowed book, making it available for others.- Parameters:
bookId- the ID of the book to return- Returns:
trueif the return was successful,falseotherwise
-