This project is a backend for a social networking application, featuring user management, friend requests, user activities, and more. It is built using Django and Django REST Framework.
- User signup and login with JWT authentication.
- Friend request system.
- User activity logging.
- Redis caching for optimized performance.
- API endpoints for searching users and managing friend requests.
- Clone the repository:
git clone [<your-repo-url>](https://github.com/VaibhavGupta2408/Accuknox_Backend_Assignment)
- Create and activate a virtual environment:
python -m venv env source env/bin/activate # On Windows: env\Scripts\activate
- Install the required dependencies:
pip install -r requirements.txt - Like : Install Django and Django Rest Framework `pip install django djangorestframework psycopg2-binary djangorestframework-simplejwt django-cors-headers`
- Set up PostgreSQL (or any other preferred database):
- Create a database and update the DATABASES setting in settings.py.
- PostgreSQL:
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'social_network_db', 'USER': 'your_db_user', 'PASSWORD': 'your_db_password', 'HOST': 'localhost', 'PORT': '5432', } }
- Run database migrations:
python manage.py makemigrations python manage.py migrate
- Run Redis (if not already running):
redis-server.exe # On Windows
- Run the Django development server:
python manage.py runserver
- Create a superuser for the admin panel (optional):
python manage.py createsuperuser
- URL:
/api/users/signup/
- Method: POST
- Payload: { "email": "[email protected]", "password": "yourpassword" }
- Response: User creation success message.
- URL:
/api/users/login/
- Method: POST
- Payload: { "email": "[email protected]", "password": "yourpassword" }
- Response: JWT access and refresh tokens.
- URL:
/api/users/friend-request/send/<receiver_id>/
- Method: POST
- Response: Success or failure message.
- URL:
/api/users/friend-request/respond/<request_id>/<action>/
- Method: POST
- Actions: Accept or Reject (accept, reject)
- Response: Friend request status update message.
- URL:
/api/users/friends/
- Method: GET
- Response: List of user's friends.
[ { "id": 1, "email": "[email protected]", "username": "friend1", "status": "Accepted" } ]
-- Because there is no friend (In arnav case)
- URL:
/api/users/search/
- Method: GET
- Query Param: search=
- Response: List of users matching the search keyword.
- Download the Postman Collection
- To containerize the application and run it using Docker, follow these steps:
-
Ensure Docker is installed on your system:
You can install Docker from here.
-
Build the Docker image:
docker-compose build
-
Run the Docker containers:
docker-compose up
- This will start the following services:
- PostgreSQL database: The application uses PostgreSQL as the database.
- Redis: Redis is used for caching.
- Django app: The Django REST API will be available at http://localhost:8000.
- Accessing the app:
- Open http://localhost:8000 in your browser to interact with the API or check API endpoints using Postman.
- The PostgreSQL database is accessible at localhost:5432.
- Example for accessing the database:
Host: localhost Port: 5432 Username: <your_db_user> Password: <your_db_password>
-
Running migrations inside the Docker container: After starting the containers, you may need to run migrations for the Django app:
docker-compose exec web python manage.py migrate
-
Stop and remove the Docker containers: To stop the containers, run:
docker-compose down
- Python 3.x
- Django
- Django REST Framework
- djangorestframework-simplejwt
- psycopg2
- Redis
- Docker
- All dependencies are listed in requirements.txt.