From d653d239f7b88494fefe9f2a6cd6aaa6119c741f Mon Sep 17 00:00:00 2001 From: Shivayan09 <147698014+Shivayan09@users.noreply.github.com> Date: Fri, 4 Oct 2024 20:22:37 +0530 Subject: [PATCH] Update Book.java --- .../java/com/libraryman_api/book/Book.java | 65 ++++++++++++++++--- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/libraryman_api/book/Book.java b/src/main/java/com/libraryman_api/book/Book.java index b4d3f8e..79e6528 100644 --- a/src/main/java/com/libraryman_api/book/Book.java +++ b/src/main/java/com/libraryman_api/book/Book.java @@ -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; @@ -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; } @@ -78,7 +120,7 @@ public int getCopiesAvailable() { return copiesAvailable; } - + // Setters public void setTitle(String title) { this.title = title; } @@ -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{" +