A backend API for an e-commerce platform built using Spring Boot. The API manages products, customers, and orders, providing essential endpoints to power an e-commerce application.
- Manage products with CRUD operations.
- Customer management, including registration and order tracking.
- Order processing with timestamps.
- Seamless integration with relational databases using JPA and Hibernate.
Represents an item in the store that can be ordered by customers.
| Field | Type | Description |
|---|---|---|
productId |
Long |
Unique identifier for the product (auto-generated). |
name |
String |
Name of the product. |
description |
String |
Description of the product. |
price |
Integer |
Price of the product. |
storeName |
String |
Name of the store selling the product. |
Represents a customer who can place orders on the platform.
| Field | Type | Description |
|---|---|---|
customerId |
Long |
Unique identifier for the customer (auto-generated). |
name |
String |
Name of the customer. |
address |
String |
Customer's shipping address. |
password |
String |
Customer's password for authentication. |
order |
Set<Order> |
List of orders placed by the customer (bidirectional mapping). |
Note:
- To avoid infinite recursion during JSON serialization, the
@JsonIgnoreannotation is used in theorderfield.- Avoid using
toString()on bidirectional entities to prevent stack overflow errors.
Represents a purchase made by a customer.
| Field | Type | Description |
|---|---|---|
orderId |
Long |
Unique identifier for the order (auto-generated). |
customerId |
Customer |
Reference to the customer who placed the order. |
productId |
Product |
Reference to the purchased product. |
dateCreated |
LocalDateTime |
Timestamp when the order was created (auto-generated). |
This section details the available API endpoints for managing customers in the e-commerce platform.
- Endpoint:
api/customer?customerId=6 - Method:
GET - Description: Retrieves the details of a customer by their unique
customerId. It also returns the IDs of the orders placed by the customer. - Query Parameters:
customerId(Long): The unique identifier of the customer.
- Response:
- Success (200 OK): Returns a
CustomerVoobject containing the customer's information along with a list oforderIds. - Failure (400 NOT FOUND): Returns a failure message if the customer does not exist.
- Success (200 OK): Returns a
- Endpoint:
api/customer - Method:
POST - Request Body:
{
"name": "Thomas",
"password": "Test123",
"address": "Tampines st 342 blk 123"
}- Description: Creates a new customer by accepting the customer's
Name,Password, andAddressin the request body. - Response:
- Success (200 OK): Returns a
CustomerVoobject containing the customer's information along with a list oforderIds.
- Success (200 OK): Returns a
- Endpoint:
api/customer?customerId=6 - Method:
DELETE - Description: Deletes a customer based on
customerId. It also deletes all orders placed by that customer. - Query Parameters:
customerId(Long): The unique identifier of the customer.
- Response:
- Success (200 OK): Returns a
Longobject representing the customerId of the customer deleted. - Failure (404 Not Found): Returns a failure message if the customer does not exist.
- Success (200 OK): Returns a
- Endpoint:
api/customer/orders?customerId=9 - Method:
GET - Description: Gets all orders of a customer based on
customerId. - Query Parameters:
customerId(Long): The unique identifier of the customer.
- Response:
- Success (200 OK): Returns a
Set<Order>object representing all the orders placed by this customer. - Failure (404 Not Found): Returns a failure message if the customer does not exist.
- Success (200 OK): Returns a
- Endpoint:
api/product?productId=1 - Method:
GET - Description: Retrieves the details of a product by their unique
productId.productId(Long): The unique identifier of the product.
- Response:
- Success (200 OK): Returns a
ProductVoobject containing the product's information. - Failure (404 NOT FOUND): Returns a failure message if the product does not exist.
- Success (200 OK): Returns a
- Endpoint:
api/product/all - Method:
GET - Description: Retrieves the details of all prodects.
- Response:
- Success (200 OK): Returns a list of
ProductVoobject containing all the products in the database
- Success (200 OK): Returns a list of
- Endpoint:
api/product - Method:
POST - Request Body:
{
"name": "Slytherin cup",
"description": "cup belonging to the house Slytherin in harry potter",
"price": 20,
"storeName": "store D"
}- Description: Adds a new product to the database.
- Response:
- Success (200 OK): Returns the
ProductVoobject containing the product just added in the database
- Success (200 OK): Returns the
- Endpoint:
api/order - Method:
POST - Request Body:
{
"customerId": 6,
"productId": 6
}- Description: Adds a new order to the database.
- Response:
- Success (200 OK): Returns a
OrderVoobject containing the order's information. - Failure (404 NOT FOUND): Returns a failure message if the productId or customerId does not exist.
- Success (200 OK): Returns a
- Endpoint:
api/order?orderId=12 - Method:
DELETE - Description: Deletes a product from the database based on their unique
orderId.orderId(Long): The unique identifier of the order.
- Response:
- Success (200 OK): Returns a
OrderVoobject containing the order's information. - Failure (404 NOT FOUND): Returns a failure message if the orderId does not exist.
- Success (200 OK): Returns a
Things to do: error handling, delete product.
- Backend Framework: Spring Boot
- ORM: Hibernate (JPA)
- Database: MySQL/PostgreSQL (can be configured)
- Serialization: Jackson (for JSON processing)
- Build Tool: Maven
- Java 17+
- Maven
- MySQL/PostgreSQL database
- Clone the repository:
git clone https://github.com/your-username/ecommerce-backend.git cd ecommerce-backend