SpringBootLibrary
Loading...
Searching...
No Matches
com.example.restapi.service.BookService Class Reference

Public Member Functions

List< Book > getAllBooks ()
Optional< Book > getBookById (Long id)
Book createBook (Book book)
Book updateBook (Long id, Book bookDetails) throws Exception
void deleteBook (Long id)
boolean borrowBook (Long bookId, Long userId)
boolean returnBook (Long bookId)

Detailed Description

Service class that provides business logic for managing Book and borrowing operations.

Definition at line 16 of file BookService.java.

Member Function Documentation

◆ borrowBook()

boolean com.example.restapi.service.BookService.borrowBook ( Long bookId,
Long userId )

Definition at line 80 of file BookService.java.

◆ createBook()

Book com.example.restapi.service.BookService.createBook ( Book book)

Creates a new book entry in the repository.

Parameters
bookthe Book object to be created
Returns
the created Book object

Definition at line 50 of file BookService.java.

◆ deleteBook()

void com.example.restapi.service.BookService.deleteBook ( Long id)

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

Definition at line 76 of file BookService.java.

◆ getAllBooks()

List< Book > com.example.restapi.service.BookService.getAllBooks ( )

Retrieves all books from the repository.

Returns
a list of all Book objects

Definition at line 30 of file BookService.java.

◆ getBookById()

Optional< Book > com.example.restapi.service.BookService.getBookById ( Long id)

Retrieves a book by its unique identifier.

Parameters
idthe ID of the book to retrieve
Returns
an Optional containing the found Book, or empty if not found

Definition at line 40 of file BookService.java.

◆ returnBook()

boolean com.example.restapi.service.BookService.returnBook ( Long bookId)

Returns a borrowed book, making it available for others.

Parameters
bookIdthe ID of the book to return
Returns
true if the return was successful, false otherwise

Definition at line 100 of file BookService.java.

◆ updateBook()

Book com.example.restapi.service.BookService.updateBook ( Long id,
Book bookDetails ) throws Exception

Updates an existing book's details.

Parameters
idthe ID of the book to update
bookDetailsthe updated Book details
Returns
the updated Book object
Exceptions
Exceptionif the book with the specified ID is not found

Definition at line 63 of file BookService.java.


The documentation for this class was generated from the following file: