This microservice provides a public API for users to interact with product information.
The microservice offers functionalities like:
- Product Listing: Displays a list of products, potentially filtered by facets.
- Autocomplete Search: Enables efficient product search with suggestions based on user input.
- Faceted Search: Allows users to refine their search using dynamic facets that adapt based on the chosen category, search input, and previously selected facets.
- Product Details: Provides detailed information about specific products, including variations (the same products, but with small differences such as color, size, etc.).
- Product Categories: Lists available product categories.
- Deals and Events: Highlights special offers and events related to products.
git clone https://github.com/GhostMEn20034/SMILE_SALES_product_microservice.git
on Windows (PowerShell), run:
New-Item -Path ".env" -ItemType "File"
on Unix or MacOS, run:
touch .env
mongodb_url=YourMongoDbURL
redis_cache_url=YourRedisUrl
atlas_search_product_index_name=some_index_name # The name of the search index for product search in your MongoDB cluster
atlas_search_search_terms_index_name=other_index_name # The name of the search index for search terms autocomplete in your MongoDB cluster
allowed_origins='["http://localhost:3000"]' # List of allowed origins (REMOVE SINGLE QUOTES IF YOU GONNA RUN THE APP AS DOCKER IMAGE)
relevance_threshold=0.22 # Determines minimum relevance score of search item to be not excluded
If you want to run this app you have two options:
- Run it with
python
command - Run it as Docker Image
python -m venv venv
on Windows (PowerShell), run:
.\venv\Scripts\activate.ps1
on Unix or MacOS, run:
source venv/bin/activate
pip install -r requirements.txt
export $(xargs < .env)
uvicorn src.main:app --host 0.0.0.0 --port 8000
docker build -f DockerfileLocal -t your-image-name:latest .
if you want to run the container in the production environment, build the image with the command:
docker build -f DockerfileProd -t your-image-name:latest .
docker run -d -p 8000:8000 --env-file ./.env your-image-name:latest
Before running tests, you need to export the environment variable that indicates we run the app in the test mode:
export TEST_MODE=1
Note: It's highly recommended to run tests with temporary MongoDB instance that don't store any data. Because if you forget to set TEST_MODE=1
, tests will populate data in the database where you store data, and delete all data after that.
To replace your MongoDB instance, just replace the mongodb_url
value in .env
file with the temporary instance's url.
To run tests use command:
pytest /tests