Thanks to visit codestin.com
Credit goes to github.com

Skip to content

JuhainaAlbadi/bookstore-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PageTurner Bookstore API

A REST API for an online bookstore order management system built with Spring Boot and MySQL.

Technologies Used

  • Java 21
  • Spring Boot 3.5
  • Spring Data JPA
  • MySQL 8.0
  • Maven

Project Structure

bookstore/
├── src/
│   └── main/
│       ├── java/
│       │   └── com/bookstore/
│       │       ├── BookstoreApplication.java   → Entry point of the application
│       │       ├── controller/
│       │       │   └── BookController.java     → Receives API requests and returns responses
│       │       ├── service/
│       │       │   └── BookService.java        → Business logic and stored procedure calls
│       │       ├── repository/
│       │       │   ├── BookRepository.java     → Database operations for books
│       │       │   └── OrderRepository.java    → Database operations for orders
│       │       ├── entity/
│       │       │   ├── Book.java               → Represents the books table in MySQL
│       │       │   └── Order.java              → Represents the orders table in MySQL
│       │       ├── dto/
│       │       │   ├── OrderRequest.java       → Data received from the user when placing an order
│       │       │   └── OrderResponse.java      → Data returned to the user after placing an order
│       │       └── exception/
│       │           └── BookNotFoundException.java → Custom error when a book is not found
│       └── resources/
│           └── application.properties          → Database connection and server configuration
├── bookstore_db.sql                            → Full database setup script
├── README.md                                   → Project documentation
└── pom.xml                                     → Project dependencies

Requirements

  • Java 21+
  • MySQL 8.0
  • Maven

Database Setup

  1. Open MySQL and run the file bookstore_db.sql
  2. This will create the database, tables, sample data, and stored procedure automatically

Project Setup

  1. Open src/main/resources/application.properties
  2. Update the following with your MySQL credentials: spring.datasource.username=root spring.datasource.password=your_password

How to Run

.\mvnw spring-boot:run The server will start on http://localhost:8080

API Endpoints

Books

Method Endpoint Description
GET /api/books Get all books
GET /api/books/{id} Get book by ID
GET /api/books/category/{category} Filter books by category
GET /api/books/top-selling Get top selling books

Orders

Method Endpoint Description
POST /api/orders Place a new order
GET /api/orders/customer/{customerId} Get order history for a customer
GET /api/orders/summary Get total sales summary

Business Rules

  • Orders above $100 get 10% discount automatically
  • Stock is updated automatically after each order
  • Low stock warning when less than 5 copies remain
  • Input validation on all order requests

Sample Order Request

{
    "customerId": 1,
    "bookId": 2,
    "quantity": 2
}

Sample Order Response

{
    "orderId": 1,
    "message": "SUCCESS: Order placed! Total: $90.00 Discount: $0.00",
    "success": true
}

Bonus Features

  • Exception handling with custom BookNotFoundException
  • Input validation using @NotNull and @Min annotations
  • Order history per customer
  • Category filtering
  • Sales summary report
  • Top selling books report
  • Low stock alert system

About

A REST API for an online bookstore order management system built with Spring Boot and MySQL.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages