This project is a backend service for an online bookstore, designed using Spring Boot and MySQL. It provides RESTful APIs for managing book listings, shopping cart operations, and order tracking.
online-bookstore-backend/
├── pom.xml
├── README.md
└── src/
└── main/
├── java/ │ └── com/ │ └── bookstore/
│ ├── OnlineBookstoreBackendApplication.java
│ ├── controller/
│ │ ├── BookController.java
│ │ ├── CartController.java
│ │ └── OrderController.java
│ ├── model/
│ │ ├── Book.java
│ │ ├── Cart.java
│ │ └── Order.java
│ ├── repository/
│ │ ├── BookRepository.java
│ │ ├── CartRepository.java
│ │ └── OrderRepository.java
│ └── service/
│ ├── BookService.java
│ ├── CartService.java
│ └── OrderService.java
└── resources/
├── application.properties
└── data.sql
-
Book Management:
- List all books
- Retrieve book details by ID
- Create, update, and delete books
-
Cart Operations:
- Get cart details by user ID
- Add books to the cart
- Remove books from the cart
- Clear the cart
-
Order Tracking:
- Create new orders
- Retrieve order details by order ID
- Get all orders for a specific user
- Spring Boot
- MySQL
- Maven
-
Clone the repository:
git clone <repository-url> cd online-bookstore-backend
-
Configure the database:
- Update the
src/main/resources/application.properties
file with your MySQL database connection details.
- Update the
-
Run the application:
mvn spring-boot:run
-
API Testing:
- Use Postman to test the APIs. Below are some example requests:
-
Books
GET /api/books
- Retrieve all booksGET /api/books/{id}
- Retrieve a book by IDPOST /api/books
- Create a new bookPUT /api/books/{id}
- Update a bookDELETE /api/books/{id}
- Delete a book
-
Cart
GET /api/cart/{userId}
- Get cart by user IDPOST /api/cart/{userId}
- Add a book to the cartDELETE /api/cart/{userId}/{bookId}
- Remove a book from the cartDELETE /api/cart/{userId}
- Clear the cart
-
Orders
POST /api/orders/{userId}
- Create a new orderGET /api/orders/{orderId}
- Get order by IDGET /api/orders/user/{userId}
- Get all orders for a user
The project includes a data.sql
file located in src/main/resources/
to initialize the database with sample data.
This project is licensed under the MIT License.