Project A: E-Commerce Platform
Description
Develop a complete RESTful API for an e-commerce platform allowing the management of products, users, cart, and orders.
Required Features
1. User Management
POST /api/auth/register - Registration
POST /api/auth/login - Login (returns JWT)
GET /api/users/me - User profile
PUT /api/users/me - Edit profile
User Entity:
- id, email, password, firstName, lastName
- role (CUSTOMER, ADMIN)
- createdAt, updatedAt
2. Product Catalog
GET /api/products - List products (pagination)
GET /api/products/{id} - Product details
GET /api/products/search - Search by name/category
POST /api/products - Create product (ADMIN)
PUT /api/products/{id} - Edit product (ADMIN)
DELETE /api/products/{id} - Delete product (ADMIN)
Product Entity:
- id, name, description, price, stock
- category (ManyToOne relation)
- imageUrl, active
Category Entity:
- id, name, description
3. Cart
GET /api/cart - View cart
POST /api/cart/items - Add a product
PUT /api/cart/items/{id} - Update quantity
DELETE /api/cart/items/{id} - Remove from cart
DELETE /api/cart - Empty cart
CartItem Entity:
- id, cart, product, quantity, price
4. Orders
POST /api/orders - Create order (from cart)
GET /api/orders - List orders (user)
GET /api/orders/{id} - Order details
PUT /api/orders/{id}/status - Update status (ADMIN)
GET /api/admin/orders - All orders (ADMIN)
Order Entity:
- id, user, items, totalAmount
- status (PENDING, CONFIRMED, SHIPPED, DELIVERED, CANCELLED)
- shippingAddress, createdAt
Database Schema
users
├── id (PK)
├── email (UNIQUE)
├── password
├── first_name
├── last_name
├── role
└── created_at
categories
├── id (PK)
├── name
└── description
products
├── id (PK)
├── name
├── description
├── price
├── stock
├── category_id (FK)
├── image_url
└── active
carts
├── id (PK)
└── user_id (FK, UNIQUE)
cart_items
├── id (PK)
├── cart_id (FK)
├── product_id (FK)
├── quantity
└── price
orders
├── id (PK)
├── user_id (FK)
├── total_amount
├── status
├── shipping_address
└── created_at
order_items
├── id (PK)
├── order_id (FK)
├── product_id (FK)
├── quantity
├── price
└── product_name
Business Rules
Stock
- Check availability before adding to cart
- Decrement stock upon order
- Restore stock if order is cancelled
Price
- Price in cart must be current
- Price in order is fixed
Cart
- A user has only one cart
- Cart is created automatically
- Cart is emptied after an order
Orders
- Only the user can see their orders
- Admin can see all orders
- Valid status transitions:
- PENDING -> CONFIRMED -> SHIPPED -> DELIVERED
- PENDING -> CANCELLED
- CONFIRMED -> CANCELLED
Detailed Endpoints
Authentication
POST /api/auth/register
Content-Type: application/json
{
"email": "john@example.com",
"password": "Password123!",
"firstName": "John",
"lastName": "Doe"
}
Response 201:
{
"id": 1,
"email": "john@example.com",
"firstName": "John",
"lastName": "Doe",
"role": "CUSTOMER"
}
POST /api/auth/login
Content-Type: application/json
{
"email": "john@example.com",
"password": "Password123!"
}
Response 200:
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
"type": "Bearer",
"expiresIn": 86400
}
Products
GET /api/products?page=0&size=10&category=electronics
Authorization: Bearer <token>
Response 200:
{
"content": [
{
"id": 1,
"name": "Laptop Pro",
"description": "High-performance laptop",
"price": 999.99,
"stock": 50,
"category": {
"id": 1,
"name": "Electronics"
},
"imageUrl": "https://..."
}
],
"page": 0,
"size": 10,
"totalElements": 100,
"totalPages": 10
}
Cart
POST /api/cart/items
Authorization: Bearer <token>
Content-Type: application/json
{
"productId": 1,
"quantity": 2
}
Response 200:
{
"items": [
{
"id": 1,
"product": { "id": 1, "name": "Laptop Pro", ... },
"quantity": 2,
"price": 999.99,
"subtotal": 1999.98
}
],
"totalItems": 2,
"totalAmount": 1999.98
}
Orders
POST /api/orders
Authorization: Bearer <token>
Content-Type: application/json
{
"shippingAddress": "123 Main St, City, 12345"
}
Response 201:
{
"id": 1,
"status": "PENDING",
"items": [...],
"totalAmount": 1999.98,
"shippingAddress": "123 Main St, City, 12345",
"createdAt": "2024-01-15T10:30:00"
}
Required Tests
Unit Tests
- ProductService: CRUD operations
- CartService: add, update, remove items
- OrderService: create order, validate stock
Integration Tests
- ProductController: all endpoints
- CartController: cart operations
- OrderController: order workflow
Bonus Points
| Feature | Points |
|---|---|
| Redis cache on products | +5 |
| Email notification (simulation) | +3 |
| Full-text search | +3 |
| Export orders CSV | +2 |
| Complete Docker Compose | +5 |
| Swagger documentation | +5 |
Time Estimation
| Task | Hours |
|---|---|
| Project and DB setup | 2 |
| Entities and repositories | 4 |
| Business services | 6 |
| REST Controllers | 4 |
| JWT Security | 4 |
| Tests | 6 |
| Documentation | 2 |
| Bonus | 4-8 |
| Total | 28-36 |