- Introduction
- Features
- Requirements
- Installation
- Configuration
- Usage
- API Endpoints
- Contributing
- License
Welcome to the Floating Blood Donation System Backend repository! This Django-based backend is designed to support our blood donation organization's efforts. It provides essential features for managing donors, recipients, blood types, and appointments. This document will guide you through setting up and using the backend.
- User Management: Registration, login, and profile management for donors, recipients, and administrators.
- Donor Information: Collect and manage information about donors, including blood type and medical history.
- Recipient Management: Track recipients in need of blood and manage their appointments.
- Appointment Scheduling: Allow users to schedule appointments for blood donations.
- Blood Type Matching: Find donors with compatible blood types for recipients.
Before getting started, make sure you have the following dependencies installed
- Code editor (Visual studio code recommended)
- Python (3.1 +)
- Django (3.6 +)
- Virtual Environment (optional but recommended)
- Other dependencies can be found in the requirements.txt file.
-
Clone this repository to your local machine:
git clone https://github.com/Jan-Briddhi-Foundation/bloodbankBackend.git
-
Navigate to the project directory:
cd bloodbankBackend
-
Create and activate a virtual environment (optional but recommended):
python -m venv env
- For MacOs :
source env/bin/activate
- For Windows:
env\Scripts\activate
-
Install project dependecies:
pip install -r requirements.txt
orpython -m pip install -r requirements.txt
-
Create a
.env
file in the project root and set the following environment variables: *SECRET_KEY = YOUR_SECRET_KEY DATABASE_URL = YOUR_DATABASE_URL SITE_DOMAIN = YOUR_SITE_DOMAIN SITE_NAME = YOUR_SITE_NAME EMAIL_USER = YOUR_EMAIL_USER EMAIL_PASSWORD = YOUR_EMAIL_PASSWORD SOCIAL_SECRET = YOUR_SOCIAL_SECRET GOOGLE_CLIENT_ID = YOUR_GOOGLE_CLIENT_ID GOOGLE_CLIENT_SECRET = YOUR_GOOGLE_CLIENT_SECRET FACEBOOK_CLIENT_ID = YOUR_FACEBOOK_CLIENT_ID FACEBOOK_SECRET_KEY = YOUR_FACEBOOK_SECRET_KEY TWITTER_CLIENT_ID = YOUR_TWITTER_CLIENT_ID TWITTER_SECRET_KEY = YOUR_TWITTER_SECRET_KEY
-
Run migrations to create the database tables:
- Run command
python manage.py makemigrations
- Run command
python manage.py migrate
- Run command
-
Start the development server:
- Run command
python manage.py runserver 8000
- Run command
-
Check port:
- Check url http://localhost:8000/
- Access the Django admin panel by visiting http://localhost:8000/admin/ the superuser account created earlier.
- To login the admin panel, use
admin@gmail.com
and#Dot9047
for email and password respectively - Use the admin panel to manage users, donors, patients, blood requests, hospital addresses, and other data.
- To interact with the API, explore the available endpoints (documented below) and or use tools like Postman.
-
Endpoint:
/api/auth/users/
(POST) -
Description: User registration endpoint.
-
Required Parameters:
name
email
phone
password
-
Example:
{ "name": "John Doe", "email": "john.doe@example.com", "phone": "+123456789", "password": "password", "profile": { "bloodGroup": "A+", "language": "English", "country": "USA", "city": "New York", "address": "123 Main St", "profile_pic": "profile.jpg", "profile_type": "donor" } }
-
profile_types
- donor
- patient
-
bloodGroups
- A+
- A-
- B+
- B-'
- AB+
- AB-
- O+
- O-
-
Response: Sends a confirmation email with an activation link.
- Endpoint:
/api/auth/login/
(POST) - Description: User authentication endpoint.
- Parameters:
email
password
- Response: Returns an authentication token.
- Endpoint:
/api/auth/logout/
(POST) - Description: User logout endpoint.
- Parameters: None
- Response: Logs out the user and invalidates the token.
- Endpoint:
/api/auth/users/me/
(DELETE) - Description: User deletion endpoint.
- Parameters:
current_password
- Response: Deletes the user account.
- Endpoint:
/api/auth/users/set_password/
(POST) - Description: Password change endpoint.
- Parameters:
current_password
new_password
re_new_password
- Response: Confirms the password change.
- Endpoint:
/api/auth/users/reset_password/
(POST) - Description: Password reset request endpoint.
- Parameters:
email
- Response: Sends an email with instructions to reset the password.
- Endpoint:
/api/auth/users/reset_password_confirm/<str:uid>/<str:token>/
(POST) - Description: Password reset confirm request endpoint.
- Parameters:
new_password
re_new_password
-
Success (200 OK):
- Returns a success message if password is updated successfully.
-
Bad Request (400):
- Returns validation errors if the provided data is invalid.
- Endpoint:
/social_auth/google/
(POST) - Description: Authenticate users via Google
- Parameters:
auth_token
- Response: Returns an authenicated user details, username, email and adds them in our database.
- Endpoint:
/social_auth/facebook/
(POST) - Description: Authenticate users via Facebook
- Parameters:
auth_token
- Response: Returns an authenicated user details, username, email and adds them in our database.
- Endpoint:
/social_auth/twitter/
(POST) - Description: Authenticate users via Twitter
- Parameters:
access_token_key
access_token_secret
- Response: Returns an authenicated user details, username, email and adds them in our database.
-
Endpoint:
/api/home/
(GET) -
Description: Retrieves user's home page details.
-
Permissions: User must be authenticated.
- Success (200 OK):
- Returns user's home page details.
- For donors: Redirects to 'donor_home'.
- For patients: Redirects to 'patient_home'.
- For other profiles: Redirects to 'user_details'.
- Returns user's home page details.
- User Details Update (200 OK):
- If user's profile doesn't exist, creates a profile, updates user details, and returns a success message.
- Success (200 OK):
-
Endpoint:
/api/profile-details/
(POST) -
Description: Updates user's profile details.
-
Permissions: User must be authenticated.
- Method: POST
- Parameters:
city
country
bloodGroup
profile_type
-
Success (200 OK):
- Returns a success message if user details are updated successfully.
-
Bad Request (400):
- Returns validation errors if the provided data is invalid.
-
Endpoint:
/api/donor-home/
(GET) -
Description: Retrieves blood donation requests for donors.
-
Permissions: User must be authenticated.
- Success (200 OK):
- Returns a list of blood donation requests.
- Success (200 OK):
-
Endpoint:
/api/donation-criteria/
(POST) -
Description: Validates and processes user's donation criteria form.
-
Permissions: User must be authenticated.
- Method: POST
- Parameters:
qualify
(Boolean Value)
-
Success (200 OK):
- Returns a success message if the user is eligible or NOT for donation.
-
Bad Request (400):
- Returns validation errors if the provided data is invalid.
-
Endpoint:
/api/questions/
(POST, GET) -
Description: For adding and retriving questions donation criteria form.
-
Permissions: User must be authenticated and be an admin.
- Method: (POST)
- Parameters:
question
- Permissions: User must be an admin.
- Method: (GET)
- Response (200 OK):
- Returns all questions donation criteria form.
-
Success (200 OK):
- Returns a success message if the user is eligible or NOT for donation.
-
Bad Request (400):
- Returns validation errors if the provided data is invalid.
- Endpoint:
/api/questions/<int:question_id>/
(DELETE) - Description: Donation Criteria question deletion endpoint.
- Permissions: User must be an admin.
- Parameters: None
- Response: Deletes the donation criteria question.
- Endpoint:
/api/questions/<int:question_id>/
(PUT) - Description: Donation Criteria question update endpoint.
- Permissions: User must be an admin.
- Parameters: None
- Response: Modifies the donation criteria question.
-
Endpoint:
/api/hospital-address/
(POST) -
Description: Adds a hospital address.
-
Permissions: User must be authenticated.
- Method: POST
- Parameters:
name
address
email
-
Success (200 OK):
- Returns a success message if the hospital is added successfully.
-
Bad Request (400):
- Returns validation errors if the provided data is invalid.
-
Endpoint:
/api/donation-agreement/
(POST, GET)- GET: Retrieves user's donation agreement forms.
- POST: Submits a donation agreement request.
-
Description: Allows users to view and submit donation agreements.
-
Permissions: User must be authenticated.
- Response (200 OK):
- Returns a list of user's donation agreements.
- Request:
- Donation agreement data in the request body.
- Parameters:
hospital_address
- Response:
- Returns a success message if the donation agreement is sent successfully.
- Returns an error message if the provided data is invalid.
- Response (200 OK):
-
Endpoint:
/api/profile/
(POST, GET)- GET: Retrieves user's profile info.
- POST: Updates user's profile info.
-
Description: Allows users to view and edit their profile details.
-
Permissions: User must be authenticated.
- Response (200 OK):
- Returns user's profile.
- Request:
- User and profile data in the request body.
- Response:
- Returns a success message if the profile is updated successfully.
- Returns an error message if the provided data is invalid.
- Parameters:
name
email
phone
bloodGroup
langauge
country
city
address
profile_pic
- Response (200 OK):
-
Endpoint:
/api/request-blood/
(POST)- POST: Submits a blood request.
-
Description: Allows users to request blood donations.
-
Permissions: User must be authenticated.
- Request:
- Blood request data in the request body.
- Response:
- Returns a success message if the blood request is sent successfully.
- Returns an error message if the provided data is invalid.
- Parameters:
quantity
date_needed
- Request:
-
Endpoint:
/api/patient-history/
(GET) -
Description: Retrieves the blood donation history for the patient and provides the User's profile info.
-
Permissions: User must be authenticated.
- Success (200 OK):
- Returns a list of blood donation history for the patient.
- Returns User's profile information.
- Success (200 OK):
-
Endpoint:
/api/notifications/
(GET) -
Description: Retrieves requests for donors and or patients.
-
Permissions: User must be authenticated.
- Success (200 OK):
- Returns a list of requests, use the
date_created
to create notifications.
- Returns a list of requests, use the
- Success (200 OK):
We welcome contributions to improve this blood donation system. If you'd like to contribute, please follow Contribution Guidelines.
This project is not licensed yet