This is a RESTful API for an e-commerce application built with Flask, SQLAlchemy, and Stripe for payment processing. The API allows users to manage products, their shopping cart, and orders, while also providing admin functionalities for managing products and orders.
- User authentication and authorization using JWT
- Product management
- Shopping cart functionality
- Order management
- Payment processing with Stripe
- Admin functionalities for managing products and orders
- Search and filtering capabilities for products
- Flask
- Flask-SQLAlchemy
- Flask-JWT-Extended
- Marshmallow for serialization
- SQLAlchemy for ORM
- Stripe for payment processing
- SQLite for the database
-
Clone the repository:
git clone https://github.com/RavenLB/E-commerce.git cd ecommerce-api -
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate
- On Windows:
-
Install the required packages:
pip install -r requirements.txt
-
Initialize the database:
flask init-db
-
Create an admin user (optional):
flask create-admin
-
Run the application:
python run.py
-
API Endpoints:
-
Authentication:
POST /auth/register: Register a new userPOST /auth/login: Log in and receive a JWT
-
Products:
GET /products: Get all products- Query Parameters:
search: Search for products by name or descriptioncategory: Filter products by categorymin_price: Filter products with a minimum pricemax_price: Filter products with a maximum pricesort: Sort products byname,price, orcreated_atorder: Sort order, eitherascordesc
- Query Parameters:
POST /products: Create a new product (Admin only)PUT /products/<id>: Update a product (Admin only)DELETE /products/<id>: Delete a product (Admin only)
-
Cart:
GET /cart: Get the user's cartPOST /cart: Add an item to the cartPUT /cart/<item_id>: Update a cart itemDELETE /cart/<item_id>: Remove an item from the cartPOST /cart/checkout: Checkout and create an order
-
Orders:
GET /orders: Get all orders for the userGET /orders/<id>: Get a specific orderPOST /orders/<id>/cancel: Cancel an order (only if pending)
-
Admin:
GET /admin/orders: Get all orders (Admin only)PUT /admin/orders/<id>/status: Update order status (Admin only)
-
This project is licensed under the MIT License - see the LICENSE file for details.