The product-service handles product catalog management, including product listings, details, search, and filtering for the e-commerce platform.
- Features
- Technology Stack
- Prerequisites
- Installation
- Environment Variables
- Running the Service
- API Endpoints
- Testing
- Product Listings: Provides a list of all available products in the catalog.
- Product Details: Retrieves detailed information for a specific product.
- Search and Filtering: Allows users to search for products by keyword and filter by attributes like price or category.
- Inventory Management: Tracks product stock and updates inventory levels.
- Language: Python
- Framework: Flask or FastAPI
- Database: PostgreSQL
- Containerization: Docker
- Python 3.8 or higher
- pip package installer
- PostgreSQL 12 or higher
- Docker (optional, for containerization)
- Clone the repository:
git clone https://github.com/your-username/product-service.git
cd product-service
- Install Dependencies:
pip install -r requirements.txt
- Environment Variables: Create a .env file in the root directory and add the following environment variables:
PORT=5000
DATABASE_URL=postgresql://user:password@localhost:5432/productdb
PORT: The port number on which the service will run.
DATABASE_URL: PostgreSQL connection string.
- Running Docker: Build the docker image:
docker build -t product-service:latest .
- Run the Docker container:
docker run -p 5000:5000 --env-file .env product-service:latest
The service should now be accessible at http://localhost:5000
Get all products
- Endpoint: GET /api/v1/products
- Description: Retrieves a list of all products.
Get product by ID
- Endpoint: GET /api/v1/products/{product_id}
- Description: Retrieves details of a specific product.
Search products
- Endpoint: GET /api/v1/products/search?q=keyword
- Description: Searches for products matching the keyword.
- Run unit tests using:
pytest
This command will execute all tests located in the tests directory.