Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Book.java #60

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 56 additions & 9 deletions src/main/java/com/libraryman_api/book/Book.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,81 @@

import jakarta.persistence.*;


/**
* Represents a book entity in the library management system.
* This class is mapped to the "books" table in the database.
*/
@Entity
public class Book {
/**
* The unique identifier for the book.
* Automatically generated using a sequence.
*/
@Id

@GeneratedValue(strategy = GenerationType.SEQUENCE,
generator = "book_id_generator")
@SequenceGenerator(name = "book_id_generator",
sequenceName = "book_id_sequence",
allocationSize = 1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "book_id_generator")
@SequenceGenerator(name = "book_id_generator", sequenceName = "book_id_sequence", allocationSize = 1)
@Column(name = "book_id")
private int bookId;

/**
* The title of the book.
* This field cannot be null.
*/
@Column(nullable = false)
private String title;

/**
* The author of the book.
*/
private String author;

/**
* The ISBN (International Standard Book Number) of the book.
* This field is unique and cannot be null.
*/
@Column(unique = true, nullable = false)
private String isbn;

/**
* The publisher of the book.
*/
private String publisher;

/**
* The year the book was published.
*/
@Column(name = "published_year")
private int publishedYear;
private String genre;

/**
* The genre of the book.
*/
private String genre;

/**
* The number of copies available in the library.
* This field cannot be null.
*/
@Column(name = "copies_available", nullable = false)
private int copiesAvailable;

/**
* Default constructor for the Book class.
*/
public Book() {
}

/**
* Constructs a new Book with the specified attributes.
*
* @param title The title of the book.
* @param author The author of the book.
* @param isbn The ISBN of the book.
* @param publisher The publisher of the book.
* @param publishedYear The year the book was published.
* @param genre The genre of the book.
* @param copiesAvailable The number of copies available.
*/
public Book(String title, String author, String isbn, String publisher, int publishedYear, String genre, int copiesAvailable) {
this.title = title;
this.author = author;
Expand All @@ -46,6 +87,7 @@ public Book(String title, String author, String isbn, String publisher, int publ
this.copiesAvailable = copiesAvailable;
}

// Getters
public int getBookId() {
return bookId;
}
Expand Down Expand Up @@ -78,7 +120,7 @@ public int getCopiesAvailable() {
return copiesAvailable;
}


// Setters
public void setTitle(String title) {
this.title = title;
}
Expand Down Expand Up @@ -107,6 +149,11 @@ public void setCopiesAvailable(int copiesAvailable) {
this.copiesAvailable = copiesAvailable;
}

/**
* Returns a string representation of the book.
*
* @return A string containing the book's details.
*/
@Override
public String toString() {
return "Books{" +
Expand Down