Skip to content

A RESTful web service built with Spring Boot for managing library books, featuring CRUD operations, book availability checks, and advanced search capabilities.

Notifications You must be signed in to change notification settings

Yassinekrn/Book-Management-WS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📚 Book Management Service

Overview

The Book Management Service is a RESTful web service built with Spring Boot that handles all book-related operations in a library management system. It provides endpoints to manage books, including adding, updating, deleting, and searching for books in the system. This service is part of a larger Service-Oriented Architecture (SOA) for a library system and can communicate with other services like Loan Management and User Management.

Features

  • 📖 Add new books: Add new books to the library's collection.
  • 🔍 Search for books: Search books by title, author, genre, or ISBN.
  • ✏️ Update book information: Modify existing book details.
  • 🗑️ Delete books: Remove books from the system.
  • 📚 Check book availability: Find out if a book is available for loan or currently on loan.

Technologies

  • Java with Spring Boot to build and manage the overall application
  • Maven for project management
  • MySQL for storing book data and related information
  • Spring Data JPA for database interactions
  • Spring Web for RESTful API creation
  • Lombok to reduce boilerplate code
  • Jersey (JAX-RS): used to create RESTful web services and handle HTTP requests for the Book Management service

Endpoints

HTTP Method Endpoint Description
POST /books Add a new book
GET /books/all Get a list of all books
GET /books/{id} Get details of a specific book by ID
GET /books/search/{keyword} Search books by title or genre
GET /books/isbn/{isbn} Search books by ISBN
GET /books/author/{author} Search books by author
PUT /books/{id} Update book details
DELETE /books/{id} Delete a book by ID
GET /books/{id}/availability Check if a book is available for loan
PUT /books/lend/{id} Lend a book (reduce available copies)
PUT /books/return/{id} Return a book (increase available copies)

Book Object

The Book object is the core entity of the Book Management Service. Below are the key attributes of a book:

Attributes:

  • id (Long) — Auto-generated unique identifier for each book.
  • title (String) — The title of the book.
  • author (String) — The author(s) of the book.
  • isbn (String) — International Standard Book Number (ISBN) for identifying the book.
  • genre (String) — The genre or category the book belongs to (e.g., Fiction, Science, History).
  • publishedYear (int) — The year the book was first published.
  • publisher (String) — The name of the publishing company.
  • description (String) — A brief summary or description of the book.
  • totalCopies (int) — The total number of copies available in the library.
  • availableCopies (int) — The number of copies currently available for loan.

Example JSON Representation:

{
    "id": 1,
    "title": "The Great Gatsby",
    "author": "F. Scott Fitzgerald",
    "isbn": "9780743273565",
    "genre": "Classic Fiction",
    "publishedYear": 1925,
    "publisher": "Scribner",
    "description": "A novel about the American dream, wealth, and social upheaval in the 1920s.",
    "totalCopies": 10,
    "availableCopies": 5
}

Explanation of Attributes:

  • id: Automatically generated by the system for unique identification.
  • title: The official title of the book.
  • author: Name(s) of the author(s).
  • isbn: Standard identifier that helps uniquely identify books worldwide.
  • genre: Describes the book category or genre (e.g., Non-fiction, Science Fiction).
  • publishedYear: The year the book was first published, useful for searches by publication date.
  • publisher: The organization that published the book, providing additional context.
  • description: A short summary to give users an idea of the book’s content.
  • totalCopies: How many physical copies the library owns.
  • availableCopies: How many of those copies are available for loan, updated dynamically.

How to Run

Prerequisites

  • Java 17+
  • Maven 3.x
  • MySQL for persistent storage

Setup

  1. Clone the repository:

    git clone https://github.com/Yassinekrn/book_management_web_service.git
    cd book_management_web_service
  2. Update application properties: If using H2/PostgreSQL, update the database connection in src/main/resources/application.properties:

    spring.datasource.url=jdbc:mysql://localhost:3306/library
    spring.datasource.username=root
    spring.datasource.password=yourpassword
  3. Build and run the application:

    mvn clean install
    mvn spring-boot:run
  4. The service will start at http://localhost:8080.

Using the Endpoints

You can use tools like Postman or curl to test the endpoints:

  • Add a new book:

    curl -X POST http://localhost:8080/books -H "Content-Type: application/json" -d '{
      "title": "The Great Gatsby",
      "author": "F. Scott Fitzgerald",
      "isbn": "9780743273565",
      "genre": "Classic Fiction",
      "publishedYear": 1925,
      "publisher": "Scribner",
      "description": "A novel about the American dream, wealth, and social upheaval in the 1920s.",
      "totalCopies": 10,
      "availableCopies": 10
    }'
  • Search for a book by title:

    curl "http://localhost:8080/books/search?title=The%20Great%20Gatsby"

Database

By default, the application uses MySQL, but it can be easily configured to use PostgreSQL or H2 according to your personal needs. Just update the application.properties file accordingly.

Future Improvements

  • Implement advanced search with filters.
  • Add support for book reservations.

Contributing

Feel free to fork this repository and submit pull requests. For significant changes, please open an issue first to discuss what you would like to change.

About

A RESTful web service built with Spring Boot for managing library books, featuring CRUD operations, book availability checks, and advanced search capabilities.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages