The Library Management System is a web application that allows users to manage books, track their availability, and facilitate borrowing and returning processes. This project is built using TypeScript, Express, and Sequelize, following Test-Driven Development (TDD) principles.
- Add new books with details like ID, title, author, and publication year.
- Borrow and return books, updating their availability status.
- View a list of available books.
- Node.js (version 14 or higher)
- Docker (for Docker setup)
- Clone the repository:
git clone https://github.com/yourusername/library-management-system.git cd library-management-system - Build the Docker image:
docker build -t library-management-system . - Run the Docker container:
docker run -p 3000:3000 library-management-system
- Access the application: Open your browser and navigate to http://localhost:3000.
- Clone the repository:
git clone https://github.com/yourusername/library-management-system.git cd library-management-system - Install dependencies:
npm install
- Run the application:
npm run start
- Access the application: Open your browser and navigate to http://localhost:3000.
The application exposes the following API routes:
-
Add a Book
- Endpoint:
POST /books - Request Body:
{ "id": "1234567890", "title": "Test Book", "author": "Author Name", "publicationYear": 2023 } - Example using Postman:
- Set the method to
POST. - URL:
http://localhost:3000/books - Body: Select
rawand chooseJSON, then paste the request body above.
- Set the method to
- Endpoint:
-
Borrow a Book
- Endpoint:
POST /books/:id/borrow - Example using Postman:
- Set the method to
POST. - URL:
http://localhost:3000/books/1234567890/borrow.
- Set the method to
- Endpoint:
-
Return a Book
- Endpoint:
POST /books/:id/return - Example using Postman:
- Set the method to
POST. - URL:
http://localhost:3000/books/1234567890/return.
- Set the method to
- Endpoint:
-
View Available Books
- Endpoint:
GET /books - Example using Postman:
- Set the method to
GET. - URL:
http://localhost:3000/books.
- Set the method to
- Endpoint:
The project includes comprehensive tests to ensure functionality. The following tests have been implemented:
- Add a Book: Verifies if a book can be added successfully.
- Borrow a Book: Tests borrowing functionality and updates availability status.
- Return a Book: Ensures returning a book makes it available again.
- Borrow Unavailable Book: Validates that borrowing an unavailable book raises an appropriate error.
- View Available Books: Confirms that the API returns a list of available books.
To run the tests, use the command:
npm run test