Skip to main content

Book Entity

The Book entity represents a book in the library system. Books can be associated with multiple users through a many-to-many relationship.

Book Fields

id
UUID
required
Unique identifier for the book. Automatically generated using @PrePersist if not provided.
gender
string
The genre of the book (e.g., “Fiction”, “Science”, “History”).
author
string
The author’s name.
image
string
URL or path to the book’s cover image.
title
string
The main title of the book.
subtitle
string
The subtitle of the book.
publisher
string
The name of the publisher.
year
string
The publication year of the book.
pages
integer
The number of pages in the book.
isbn
string
The International Standard Book Number (ISBN) for the book.
users
array
A list of users who have this book in their collection. This is a many-to-many relationship mapped by the “books” field in the User entity.

UUID Generation

The Book entity uses the @PrePersist callback to automatically generate a UUID for the id field if one is not already set:
@PrePersist
public void prePersist() {
    if (id == null) {
        id = UUID.randomUUID();
    }
}

Relationships

  • Many-to-Many with User: Books can be associated with multiple users, and users can have multiple books. The relationship is managed by the user_books join table.

BookRequest

Data Transfer Object used for creating or updating a book.

Request Fields

gender
string
The genre of the book.
author
string
The author’s name.
image
string
URL or path to the book’s cover image.
title
string
The main title of the book.
subtitle
string
The subtitle of the book.
publisher
string
The name of the publisher.
year
string
The publication year of the book.
pages
integer
The number of pages in the book.
isbn
string
The International Standard Book Number (ISBN) for the book.

Example Request

{
  "gender": "Science Fiction",
  "author": "Isaac Asimov",
  "image": "https://example.com/foundation.jpg",
  "title": "Foundation",
  "subtitle": "The First Novel in the Foundation Trilogy",
  "publisher": "Gnome Press",
  "year": "1951",
  "pages": 255,
  "isbn": "978-0-553-29335-0"
}

BookResponse

Data Transfer Object returned when retrieving book information.

Response Fields

id
UUID
required
Unique identifier of the book.
gender
string
The genre of the book.
author
string
The author’s name.
image
string
URL or path to the book’s cover image.
title
string
The main title of the book.
subtitle
string
The subtitle of the book.
publisher
string
The name of the publisher.
year
string
The publication year of the book.
pages
integer
The number of pages in the book.
isbn
string
The International Standard Book Number (ISBN) for the book.

Example Response

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "gender": "Science Fiction",
  "author": "Isaac Asimov",
  "image": "https://example.com/foundation.jpg",
  "title": "Foundation",
  "subtitle": "The First Novel in the Foundation Trilogy",
  "publisher": "Gnome Press",
  "year": "1951",
  "pages": 255,
  "isbn": "978-0-553-29335-0"
}

Build docs developers (and LLMs) love