This project is a RESTful API backend for an e-commerce platform built with Spring Boot. It provides endpoints for managing products, categories, shopping carts, user profiles, and authentication.
- User authentication and authorization
- Product management
- Category management
- Shopping cart functionality
- User profile management
- Role-based access control (Admin and User roles)
POST /login- Authenticate user and receive JWT tokenPOST /register- Register new user account
GET /products- Get all products with optional filtering- Query parameters:
cat- Filter by category IDminPrice- Filter by minimum pricemaxPrice- Filter by maximum pricecolor- Filter by color
- Query parameters:
GET /products/{id}- Get product by IDPOST /products- Create new product (Admin only)PUT /products/{id}- Update product (Admin only)DELETE /products/{id}- Delete product (Admin only)
GET /categories- Get all categoriesGET /categories/{id}- Get category by IDGET /categories/{categoryId}/products- Get all products in a categoryPOST /categories- Create new category (Admin only)PUT /categories/{id}- Update category (Admin only)DELETE /categories/{id}- Delete category (Admin only)
GET /cart- Get current user's shopping cartPOST /cart/products/{id}- Add product to cartPUT /cart/products/{id}- Update product quantity in cartDELETE /cart- Clear shopping cart
GET /profile- Get current user's profilePUT /profile- Update user profile
The API uses JWT (JSON Web Token) for authentication. Protected endpoints require a valid JWT token in the Authorization header:
Authorization: Bearer <token>
- Admin Role: Has full access to all endpoints, including product and category management
- User Role: Can access shopping cart and profile endpoints, view products and categories
- Public: Can view products and categories without authentication
The API uses standard HTTP status codes and includes error messages in the response:
200 OK- Success201 Created- Resource created400 Bad Request- Invalid request401 Unauthorized- Authentication required403 Forbidden- Insufficient permissions404 Not Found- Resource not found500 Internal Server Error- Server error
- Spring Boot
- Spring Security
- Spring Data
- JWT Authentication
- SLF4J for logging
- Clone the repository
- Configure your database settings in
application.properties - Run the application using:
./mvnw spring-boot:runThe project follows a standard Spring Boot architecture:
- Controllers: Handle HTTP requests and responses
- Services: Contain business logic
- DAOs: Handle data access
- Models: Define data structures
- Security: Configure authentication and authorization