This project is a Spring Boot application for an e-commerce platform, demonstrating the integration of MongoDB for data persistence, Spring Security for user authentication, and Redis for token blacklisting.
- MongoDB Integration: Uses MongoDB to store user information (including cart) and product details.
- Spring Security: Provides authentication and authorization mechanisms to secure user access and protect endpoints.
- Redis for Token Blacklisting: Manages tokens in Redis to enhance security by blacklisting tokens upon user logout.
- MongoDB
- Docker (to run the application in containers)
-
Clone the repository
git clone https://github.com/dkalaitz/Spring-Boot-E-commerce-API.git cd Spring-Boot-E-commerce-API
-
Configure MongoDB
- Ensure MongoDB is running either locally or update
application.properties
with your MongoDB connection details.
- Ensure MongoDB is running either locally or update
-
Configure Redis
- Ensure Redis is installed and running locally or update
application.properties
with your Redis connection details.
- Ensure Redis is installed and running locally or update
-
Accessing the Application
- Once the application is running, you can access it at
http://localhost:8080
.
- Once the application is running, you can access it at
-
Clone the repository
git clone https://github.com/dkalaitz/Spring-Boot-E-commerce-API.git cd Spring-Boot-E-commerce-API
-
Pull Docker Images
-
Ensure you have Docker installed and running on your machine.
-
Pull the Docker images for the application, MongoDB, and Redis:
docker pull dkalaitz/my-ecommerce-api docker pull mongo:latest docker pull redis:latest
-
-
Run with Docker Compose
-
Use Docker Compose to start the application along with MongoDB and Redis containers:
docker-compose up
-
-
Accessing the Application
- Once the containers are up and running, you can access the application at
http://localhost:8080
.
- Once the containers are up and running, you can access the application at
- Authentication: Use Spring Security to authenticate users and authorize access to protected endpoints.
- Product Management: Implement endpoints to manage products such as getting all products, search by name, search by type.
- User Management: Handle user registration, login, and cart management.
-
Authentication Endpoints:
/api/auth/signup
: POST request for user registration.{ "username": "exampleUsername", "email": "example123@example.com", "password": "example123", "fullName": "ExampleFirstName ExampleLastName" }
/api/auth/authenticate
: POST request to authenticate users and obtain access tokens.{ "username": "exampleUsername", "password": "example123", }
Note: After this request, a JWT Token is generated for future authorization.
/api/auth/logout
: POST request to invalidate tokens and logout users. JWT Token is required (Auth Type = Bearer Token).
-
Secure Endpoints: Document endpoints that require authentication and authorization. JWT Token is required (Auth Type = Bearer Token)
- GET
/api/users/myProfile
: Returns user's profile details. - GET
/api/users/myCart
: Returns user's cart. - POST
api/users/addToCart
: Adds a product to user's cart. ProductId and quantity are required. - POST
api/users/removeFromCart
: Removes a product from user's cart. ProductId is required. - POST
api/users/reduceQuantity
: Reduce quantity of a product that is in user's cart. ProductId is required.
- GET
-
Accessible Endpoints without Authentication
- GET
/api/products/getTypeProducts
: Returns a specific type list of products. Type is a required parameter. - GET
api/products/searchProduct
: Returns products that have similar name with a search term. A searchTerm parameter is required. - GET
/api/products/getAllProducts
: Returns all products. - GET
/api/products/getProduct
: Returns a product based on id. ProductId parameter is required. - POST
/api/products/addProduct
: Adds a product.{ "name" : "productName" "type" : "SmartPhone" "price" : 199.99 "description" : "Product's Description" "imgURL" : "https://example.com/images/picture.jpg" }
- POST
/api/products/deleteProduct
: Deletes a product. ProductId parameter is required.
- GET