This guide outlines the steps to set up and run the backend server for the Voters Management System. The backend is built using Python and Django, with PostgreSQL as the database.
Before you begin, ensure you have the following installed:
-
Install PostgreSQL:
- Follow the official instructions for your operating system to install PostgreSQL.
-
Open PostgreSQL Terminal: Open a terminal and access PostgreSQL by running:
psql postgres
-
Create a PostgreSQL User: In the PostgreSQL terminal, create a user
rootwith the following command:CREATE USER root WITH PASSWORD 'password';
-
Create a PostgreSQL Database: Create a new database named
voters:CREATE DATABASE voters;
-
Grant Privileges: Grant all privileges on the
votersdatabase to therootuser:GRANT ALL PRIVILEGES ON DATABASE voters TO root;
-
Clone the Repository: Clone this repository to your local machine:
git clone https://github.com/oyerohabib/backend-test.git cd backend-test -
Create and Activate a Virtual Environment: Set up a Python virtual environment:
python -m venv venv source venv/bin/activate -
Install Dependencies: Install the required Python packages:
pip install -r requirements.txt
-
Configure Database: Open the
settings.pyfile and configure your database settings as follows:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'voters', 'USER': 'root', 'PASSWORD': 'password', 'HOST': 'localhost', 'PORT': '5432', } }
-
Run Migrations: Apply the database migrations:
python manage.py migrate
-
Run the Setup Script: This script will perform any necessary initial setup for your application:
python manage.py app_setup
-
Start the Server: Run the Django development server:
python manage.py runserver
Below are some key API endpoints developed for this system:
- POST
/api/v1/auth/login/: Login with email and password. - POST
/api/v1/auth/token/refresh/: Refresh JSON web token. - POST
/api/v1/auth/token/verify/: Verify the validity of a token. - POST
/api/v1/auth/users/upload-users/: Upload and process user data from a CSV file.