Skip to content

kasemsa/Library-Management-System-using-Spring-Boot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Library Management System API

This is a Spring Boot-based Library Management System API that allows librarians to manage books, patrons, and borrowing records. The API supports CRUD operations for books and patrons, as well as borrowing and returning books. It also includes JWT-based authentication for secure access to protected endpoints.

Table of Contents

  1. Prerequisites
  2. Running the Application
  3. API Endpoints
  4. Authentication
  5. Using Swagger
  6. Testing
  7. Caching
  8. Contributing

Prerequisites

Before running the application, ensure you have the following installed:

  • Java 17 or later
  • Maven or Gradle
  • MySQL or any other compatible database
  • Postman or any API testing tool (optional, if not using Swagger)

Running the Application

  1. Clone the Repository:
    git clone https://github.com/kasemsa/Library-Management-System-using-Spring-Boot.git
    cd library-management-system
    
  2. Configure the Database:

Update the application.properties file with your database credentials:

spring.datasource.url=jdbc:mysql://localhost:3306/library_management
spring.jpa.hibernate.ddl-auto=update
  1. Build the Application:

Using Maven:

mvn clean install

Using Gradle:

./gradlew build
  1. Run the Application: Using Maven:
mvn spring-boot:run

Using Gradle:

./gradlew bootRun
  1. Access the API: The API will be available at http://localhost:8080.

API Endpoints

Book Management:

GET /api/books: Retrieve a list of all books.

GET /api/books/{id}: Retrieve details of a specific book by ID.

POST /api/books: Add a new book to the library.

PUT /api/books/{id}: Update an existing book's information.

DELETE /api/books/{id}: Remove a book from the library.

Patron Management:

GET /api/patrons: Retrieve a list of all patrons.

GET /api/patrons/{id}: Retrieve details of a specific patron by ID.

POST /api/patrons: Add a new patron to the system.

Borrowing Management:

POST /api/borrow/{bookId}/patron/{patronId}: Allow a patron to borrow a book.

PUT /api/return/{bookId}/patron/{patronId}: Record the return of a borrowed book by a patron.

Authentication The API uses JWT (JSON Web Token) for authentication. To access protected endpoints, follow these steps:

  1. Register a User:

Send a POST request to /api/users with the following payload:

{
  "username": "admin",
  "email": "admin@example.com",
  "password": "password123"
}
  1. Login:

Send a POST request to /auth/login with the following payload:

{
  "username": "admin",
  "password": "password123"
}

.The response will include a JWT token:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
  1. Use the Token:

    Include the token in the Authorization header for protected endpoints:

    Authorization: Bearer <your-jwt-token>

Using Swagger

The API documentation is available via Swagger UI. Follow these steps to explore and test the API:

  1. Start the application (see Running the Application).

  2. Open your browser and navigate to:

http://localhost:8080/swagger-ui.html
  1. Use the Swagger UI to:

    .View detailed documentation for each endpoint.

    .Test endpoints directly from the UI.

    .View example requests and responses.

Testing

To run the tests, use the following commands:

Maven:

mvn test

Gradle:

./gradlew test

Caching

The API uses Spring's caching mechanisms to improve performance. Frequently accessed data, such as book details and patron information, is cached.

Cache Configuration:

Cache size: 100 entries
Cache expiration: 60 seconds after last access

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.

  2. Create a new branch for your feature or bugfix.

  3. Submit a pull request with a detailed description of your changes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages