Welcome to the world of online book shopping, where stories come to life with just a click! 📚 This project isn't just any online bookstore, it's a dynamic platform crafted with Spring Boot magic, ready to whisk you away on a literary adventure.
The Online Bookstore API isn't just a solution, it's a gateway to a realm of endless literary possibilities. 🌟 Seamlessly blending cutting-edge web technologies with industry best practices, this project sets the stage for a smooth and secure online book shopping experience.
- Spring Boot: Your trusty steed for crafting Java-based web applications.
- Spring Security: Guardian of the gates, ensuring only authorized users enter.
- Spring Data JPA: Your faithful guide through the labyrinth of database interactions.
- Spring Web: Your ticket to the world of web-based applications with Spring MVC.
- Maven: Your organizational maestro, orchestrating dependencies with finesse.
- Hibernate: The sorcerer's apprentice, wielding ORM magic.
- Liquibase: The architect of database transformations, sculpting data with precision.
- MySQL: Your sturdy stronghold, guarding precious data.
- MapStruct: The cartographer, charting the territories of object mapping.
- JUnit: Your trusty sword in the battle for code quality.
- Mockito: The shape-shifter, conjuring illusions for seamless testing.
- Docker: Your vessel for encapsulating the essence of your application.
- Testcontainers: Your genie in a bottle, conjuring ephemeral environments for testing prowess.
- User Registration and Authentication: Join the literary community with ease and security.
- Book Browsing and Searching: Embark on a quest through the vast library of literature.
- Shopping Cart Management: Gather your literary treasures with finesse.
- Order Processing: Seal the deal and bring your chosen tales home.
- User Profile Management: Customize your literary journey with personalized settings.
- Secure RESTful API Endpoints: Fortified endpoints, ensuring safe passage for data travelers.
-
Clone the repository:
git clone https://github.com/nklimovych/book-store.git cd book-store
-
Set Environment Variables:
Create a
.env
file in the project root directory and populate it with the following environment variables:MYSQL_USER=root MYSQL_ROOT_PASSWORD=password MYSQL_DATABASE=bookstore MYSQL_LOCAL_PORT=3307 MYSQL_DOCKER_PORT=3306 SPRING_LOCAL_PORT=8080 SPRING_DOCKER_PORT=8080 DEBUG_PORT=5005 JWT_SECRET=JustAnotherSuperSecretString1234! JWT_EXPIRATION=3600000
-
Build and Run the Docker Containers:
docker-compose up --build
-
Access the Application:
Open your browser and go to http://localhost:8080/api/swagger-ui/index.html#/ to access the Swagger API documentation.
-
Stop and Remove Containers:
To stop and remove the containers created by the Compose file, use the docker-compose down command:
docker-compose down
Explore the detailed API documentation generated by Swagger to understand the various endpoints and their functionalities.
Follow the next steps:
- Open Auth Management registration endpoint:
- Click on the "Try it out" button:
- Register a new user with unique email and press "Execute"
- If registration passes successfully, you'll see your registration data:
- Open Auth Management login endpoint:
- Click on the "Try it out" button:
- Use registered login and password:
- Copy token from response body:
- Click on the "Authorize" button on the top of the page:
- Paste the token in the field, and click "Authorize":
- Now you can use all endpoints
- Register a new user:
POST /api/auth/register
{ "email": "user@mail.com", "password": "password", "repeatPassword": "password", "firstName": "Owly", "lastName": "User", "shippingAddress": "Main St. 57, Lviv" }
- Authenticate as user:
POST /api/auth/login
{ "email": "user@mail.com", "password": "password" }
- If you want to use admin endpoints, fill free to use credentials below:
{ "email": "admin@mail.com", "password": "password" }
- Retrieve book catalog:
GET /api/books
- Retrieve book details:
GET /api/books/{id}
- Create a new book:
POST /api/books
- Update a specific book:
PUT /api/books/{id}
- Delete a specific book:
DELETE /api/books/{id}
- Create a new category:
POST /api/categories
- Retrieve all categories:
GET /api/categories
- Retrieve a specific category by its id:
GET /api/categories/{id}
- Update a specific category:
PUT /api/categories/{id}
- Delete a specific category:
DELETE /api/categories/{id}
- Retrieve books by a specific category:
GET /api/categories/{id}/books
- Retrieve user's shopping cart:
GET /api/cart
- Add a book to the shopping cart:
POST /api/cart
- Update quantity of a book in the shopping cart:
PUT /api/cart/cart-items/{cartItemId}
- Remove a book from the shopping cart:
DELETE /api/cart/cart-items/{cartItemId}
- Place an order:
POST /api/orders
- Retrieve user's order history:
GET /api/orders
- Retrieve all OrderItems for a specific order:
GET /api/orders/{orderId}/items
- Retrieve a specific OrderItem within an order:
GET /api/orders/{orderId}/items/{itemId}
- Update order status:
PATCH /api/orders/{id}
Problem: Managing database changes consistently across different environments.
Solution: Used Liquibase to automate database migrations.
Steps:
- Created changelog files for database changes.
- Configured Liquibase to run these changelogs during application startup.
Problem: Ensuring consistent and reliable environments for development, testing, and production.
Solution: Used Docker to containerize the application and its dependencies.
Steps:
- Created Dockerfiles to define the application and database images.
- Used docker-compose to set up and manage a multi-container environment.
- Tested the application in a Dockerized environment to ensure consistency across different stages.