Welcome to the Book Store API! This project serves as the backbone for an online bookstore, offering essential functionalities for searching, browsing, and purchasing books. Inspired by the need for a robust and efficient solution, the Book Store API aims to tackle the challenges faced by online book retailers, providing a seamless experience for both users and administrators.
- Spring Boot: For building the application framework.
- Spring Security: To handle authentication and authorization.
- Spring Data JPA: For database interactions using JPA.
- Spring Web: For building web-based applications with Spring MVC.
- Swagger: For API documentation and testing.
- Hibernate: As the ORM tool.
- MySQL: For the relational database.
- Liquibase: For database schema versioning and management.
- Docker: For containerizing the application.
- JUnit: For unit testing.
- Mockito: For mocking in tests.
- Testcontainers: For providing lightweight, disposable containers for integration testing, ensuring consistent and isolated test environments.
- Maven: For project management and dependency management.
- Endpoint:
POST /api/auth/register
- Description: Registers a new user in the application.
- Request Body:
{ "email": "[email protected]", "password": "superpass", "repeatPassword": "superpass", "firstName": "Rick", "lastName": "Sanchez", "shippingAddress": "Washington, USA, Earth" }
- Endpoint:
POST /api/auth/login
- Description: Logs in an existing user and returns a token.
- Request Body:
{ "email": "[email protected]", "password": "superpass" }
- Endpoint:
POST /api/auth/login
- Description: Logs in an admin user and returns a token.
- Request Body:
{ "email": "[email protected]", "password": "superpass" }
Once a user or admin logs in, they receive a token that must be used to access protected endpoints. There are two ways to use this token:
-
Bearer Token Authentication:
- Include the token in the
Authorization
header of your requests. - Example:
GET /api/protected-endpoint Authorization: Bearer jwt_token_here
- Include the token in the
-
Basic Authentication:
- Include the credentials in the
Authorization
header of your requests in the formatBasic base64(email:password)
. - Example:
GET /api/protected-endpoint Authorization: Basic base64_encoded_credentials
- Include the credentials in the
- The credentials provided above can be used for testing purposes.
- List all books:
GET /api/books
- Get book details:
GET /api/books/{id}
- Add new book:
POST /api/books
(Admin only) - Update book:
PUT /api/books/{id}
(Admin only) - Delete book:
DELETE /api/books/{id}
(Admin only)
- List all categories:
GET /api/categories
- Get category by id:
GET /api/categories/{id}
- Get all books by category:
GET /api/categories/{id}/books
- Add new category:
POST /api/categories
(Admin only) - Update category:
PUT /api/categories/{id}
(Admin only) - Delete category:
DELETE /api/categories/{id}
(Admin only)
- Get user's cart:
GET /api/cart
- Add book to cart:
POST /api/cart
- Remove item from cart:
DELETE /api/cart/{itemId}
- Update book quantity in cart:
PUT /api/cart/{itemId}
- Get order history:
GET /api/orders
- Place order:
POST /api/orders
- Get all items from order:
GET /api/orders/{id}/items
- Get specific item from order:
GET /api/orders/{orderId}/items/{itemId}
- Update order status:
PATCH /api/orders/{id}
(Admin only)
Follow these steps to run application:
-
Clone the repository:
git clone https://github.com/VolandevlodD/book-store
-
Navigate to the project directory:
cd book-store
-
Set Environment Variables:
Create a
.env
file in the project root directory and populate it with the following environment variables:MYSQLDB_USER=your_db_username MYSQLDB_ROOT_PASSWORD=your_db_password MYSQLDB_DATABASE=your_db_name MYSQLDB_LOCAL_PORT=3307 MYSQLDB_DOCKER_PORT=3306 SPRING_LOCAL_PORT=8080 SPRING_DOCKER_PORT=8080 DEBUG_PORT=5050 JWT_SECRET=your_jwt_secret JWT_EXPIRATION=your_jwt_expiration
-
Build the project:
./mvnw clean install
-
Build and Run the Docker Containers:
- Make sure you have Docker installed on your machine. If not, please visit the official Docker website and download it before proceeding.
docker-compose up
-
Access the Application:
Open your browser and go to http://localhost:8080/api/swagger-ui.html to access the Swagger API documentation.
You can fork and use the Postman collection by clicking the button below:
Explore the features of our API in this video:
Feel free to connect with me on LinkedIn:
I'm always open to networking and discussing new opportunities!