π Online Book Store API
A comprehensive backend application for managing an online bookstore, built with Java and Spring Boot. It offers full CRUD functionality for books, categories, shopping carts, and orders, along with user authentication and role-based access control.
π― Project Overview
This application serves as the backend for an online book store, supporting two roles:
β’ Shopper (User)
- Sign up / Sign in
- Browse books by category or all at once
- View book details
- Add/remove books to/from cart
- Place orders and view order history
β’ Manager (Admin)
- Add, update, delete books
- Manage categories
- Update order status
The system is structured around 8 core domain models:
User, Role, Book, Category, ShoppingCart, CartItem, Order, OrderItem
π Technologies & Tools
| Tool | Description |
|---|---|
| Java 21 | Core language |
| Spring Boot 3.4.1 | Main framework |
| Spring Security | Authentication & authorization |
| Spring Data JPA | Data persistence |
| JWT | Token-based authentication |
| MapStruct | DTO mapping |
| Liquibase | DB schema management |
| Hibernate Validator | Input validation |
| Testcontainers | Integration tests with Docker |
| MySQL / H2 | Databases (prod/test) |
| Swagger | API documentation |
| Lombok | Less boilerplate |
| Checkstyle | Code quality |
π API Endpoints Overview
β Authentication
POST /api/auth/registerβ Register a new userPOST /api/auth/loginβ Login and receive a JWT token
π Book
GET /api/booksβ List all booksGET /api/books/{id}β View book by IDPOST /api/booksβ Add a book (admin only)PUT /api/books/{id}β Update bookDELETE /api/books/{id}β Delete bookGET /api/books/searchβ Search books
π·οΈ Category
POST /api/categoriesβ Add a categoryGET /api/categoriesβ List categoriesGET /api/categories/{id}β View categoryPUT /api/categories/{id}β Update categoryDELETE /api/categories/{id}β Delete categoryGET /api/categories/{id}/booksβ View books in category
π Shopping Cart
GET /api/cartβ View cartPOST /api/cartβ Add item to cartPUT /api/cart/cart-items/{cartItemId}β Update itemDELETE /api/cart/cart-items/{cartItemId}β Remove item
π¦ Order
POST /api/ordersβ Place an orderGET /api/ordersβ View order historyGET /api/orders/{orderId}/itemsβ Items in an orderGET /api/orders/{orderId}/items/{itemId}β View specific itemPATCH /api/orders/{id}β Update order status
π Live Demo
π§ͺ Swagger UI after starting the application locally:
http://localhost:8080/swagger-ui.html
πΉ YouTube Demo:
https://youtu.be/K64DTGeaMEM
π Default Users
| Role | Password | |
|---|---|---|
| Admin | admin@example.com | adminExample |
| User | user@example.com | userExample |
π οΈ These accounts are automatically created on application startup via DataInitializer.
βοΈ Setup Instructions
β Prerequisites
- Java 17+
- Docker
- Maven
π§ͺ Clone & Run Locally
# Clone repo
git clone https://github.com/dedis34/SpringBoot-BookShop.git
# Package app
./mvnw clean package
# Run app with Docker
docker compose up