- Requirements
- How to Run the Service
- 1st Way ( Following steps.)
- 2nd Way (Conainerization)
List the prerequisites and dependencies required to run the project. Include links or version numbers (Installation).
- Python (3.11.4)
- Django (4.1.13)
- djangorestframework (3.14.0)
- pymongo (3.12.3)
This project uses MongoDB as its database backend. Ensure that MongoDB is installed and running on your system.
The project interacts with a MongoDB database named mydb:
# Connect to MongoDB shell
mongo
# Create the mydb database
use mydb
# Create collections (users, organizations, permissions)
db.createCollection("users")
db.createCollection("organizations")which contains the following collections:
users: Stores information about users.organizations: Stores information about organizations.
Ensure that these collections are present in your MongoDB database for the project to function correctly.
Provide step-by-step instructions to set up the project locally.
-
Clone the Repository: Begin by cloning the repository to your local machine:
https://github.com/Ahmed-Naserelden/Wholesale-Registration-Service.git
-
Navigate to the Project Directory: Move into the project directory:
cd Wholesale-Registration-Service -
Create a Virtual Environment (Optional but Recommended): It's good practice to work within a virtual environment to keep your dependencies isolated:
python -m venv venv
-
Activate the Virtual Environment: Activate the virtual environment to start using it:
- On Windows:
venv\Scripts\activate
- On macOS/Linux:
source venv/bin/activate -
Install Dependencies: Use pip to install the project dependencies listed in the requirements.txt file:
pip install -r requirements.txt
Once installed, configure your Django project's
wholesale/settings.pyfile to use MongoDB as the database backend. Here's an example configuration:Note:
For local development, the project is configured to connect to a MongoDB database running on localhost. Don't edit anything in the database configuration
wholesale/settings.pyif you intend to connect with the local environment.# wholesale/settings.py DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'mydb', # Specify the name of your MongoDB database 'ENFORCE_SCHEMA': False, 'CLIENT': { 'host': 'your_cluster_name.mongodb.net', # MongoDB Cloud host 'port': 27017, # MongoDB default port 'username': 'your_username', # MongoDB username 'password': 'your_password', # MongoDB password 'authSource': 'admin', # Authentication database 'ssl': True, # Enable SSL encryption 'retryWrites': True, # Enable retryable writes 'retryReads': True, # Enable retryable reads } } }
-
Migrate the Database: Run database migrations to create necessary tables:
python manage.py migrate
-
Create a Superuser: You can create a superuser to access the Django admin interface and perform administrative tasks:
python manage.py createsuperuser
-
Run the Development Server: Start the Django development server to run the project locally:
python manage.py runserver 0.0.0.0:8000
- Navigate to the project directory:
cd Wholesale-Registration-Service/- Build and run the Docker containers:
docker-compose up- Open your browser and navigate to:
http://localhost:8000/Want to quickly test the API endpoints? Click the button below to run the Postman collection:
If you have any questions, feedback, or encounter any issues while setting up the project, feel free to reach out! We're here to help.