The Online Book Store application is a platform designed to facilitate the buying and selling of books.
This is back-end part of application developed on Java.
- Java 17
- Maven
- Docker
- Swagger
- Spring Data (version 3.2.1; is common for all Spring tools from Spring framework 3.2.1)
- Spring Boot Web (RESTful API)
- Spring Boot Security
- Spring Boot Testing (JUnit, Mockito, MockMvc, Testcontainers)
- Lombok
- MapStruct
- Hibernate
- MySQL (version 8.0.33)
- Liquibase
In this app we will have the following domain models (entities):
- User: Contains information about the registered user including their authentication details and personal information.
- Role: Represents the role of a user in the system, for example, admin or user.
- Book: Represents a book available in the store.
- Category: Represents a category that a book can belong to.
- ShoppingCart: Represents a user's shopping cart.
- CartItem: Represents an item in a user's shopping cart.
- Order: Represents an order placed by a user.
- OrderItem: Represents an item in a user's order.
People involved:
- Shopper (User): Someone who looks at books, puts them in a basket (shopping cart), and buys them.
- Manager (Admin): Someone who arranges the books on the shelf and watches what gets bought.
Things Shoppers Can Do:
- Join and sign in:
- Join the store.
- Sign in to look at books and buy them.
- Look at and search for books:
- Look at all the books.
- Look closely at one book.
- Find a book by typing its name.
- Look at bookshelf sections:
- See all bookshelf sections.
- See all books in one section.
- Use the basket:
- Put a book in the basket.
- Look inside the basket.
- Take a book out of the basket.
- Buying books:
- Buy all the books in the basket.
- Look at past receipts.
- Look at receipts:
- See all books on one receipt.
- Look closely at one book on a receipt.
Things Managers Can Do:
- Arrange books:
- Add a new book to the store.
- Change details of a book.
- Remove a book from the store.
- Organize bookshelf sections:
- Make a new bookshelf section.
- Change details of a section.
- Remove a section.
- Look at and change receipts:
- Change the status of a receipt, like "Shipped" or "Delivered".
All endpoints were documented using Swagger
- Available for non authenticated users:
- POST: /api/auth/register
- POST: /api/auth/login
- Available for users with role USER
- GET: /api/books
- GET: /api/books/{id}
- GET: /api/categories
- GET: /api/categories/{id}
- GET: /api/categories/{id}/books
- GET: /api/cart
- POST: /api/cart
- PUT: /api/cart/cart-items/{cartItemId}
- DELETE: /api/cart/cart-items/{cartItemId}
- GET: /api/orders
- POST: /api/orders
- GET: /api/orders/{orderId}/items
- GET: /api/orders/{orderId}/items/{itemId}
- Available for users with role ADMIN:
- POST: /api/books/
- PUT: /api/books/{id}
- DELETE: /api/books/{id}
- POST: /api/categories
- PUT: /api/categories/{id}
- DELETE: /api/categories/{id}
- PATCH: /api/orders/{id}
- Language: Java 17. Build System: Maven (with pom.xml file).
- The app was created using SOLID principles and follows the Controller - Service - Repository architecture with REST software architectural style for APIs.
- Security was implemented using Spring Boot Security with Bearer authorization using JWT tokens.
- The Repository layer was implemented using Spring Data JPA (JpaRepository) and Custom Queries.
- All sensitive information is protected using Data Transfer Objects (DTOs).
- Validation was applied for queries, and custom validation annotations were created for email and password fields in UserRegistrationRequestDto.
- Entities fetched from the repository level were automatically transformed into DTOs using Mappers (with MapStruct plugin using Lombok and MapStruct libraries) at the service level.
- CustomGlobalExceptionHandler was added to provide more informative exception handling.
- Dynamic filtering of books by author and title was implemented using Criteria Query.
- Pagination and Swagger were integrated for specific requests.
- All endpoints were documented using Swagger.
- Liquibase was used as a database schema change management solution.
- The default user is "[email protected]" with the password "bob.admin" and the role ADMIN.
- All users registered through the common available endpoint POST: /api/auth/register will have the default role USER.
- Tests were written using Testcontainers for repository-level, Mockito for service-level, and MockMvc for controller-level.
- Finally, Docker was integrated for easy application deployment.
- Fetch this project to you local IDE.
- Open this project in your IDE.
- Create in the root directory .env file and set-up following variables:
- MYSQL_ROOT_PASSWORD
- MYSQL_USER
- MYSQL_PASSWORD
- MYSQL_DATABASE
- MYSQL_LOCAL_PORT
- MYSQL_DOCKER_PORT
- SPRING_LOCAL_PORT
- SPRING_DOCKER_PORT
- DEBUG_PORT
- JWT_EXPIRATION
- JWT_SECRET
- Example:
- Run Docker Desktop.
- Run command "docker-compose up" in Terminal in your IDE.