Skip to content

VaibhavGupta2408/Accuknox_Backend_Assignment

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Social Networking API Project

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.

Features:

  • 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.

Installation Steps

  1. Clone the repository:
    git clone [<your-repo-url>](https://github.com/VaibhavGupta2408/Accuknox_Backend_Assignment)
    
  2. Create and activate a virtual environment:
    python -m venv env
     source env/bin/activate  # On Windows: env\Scripts\activate
    
  3. 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`
    
  4. Set up PostgreSQL (or any other preferred database): image
    • 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',
        }
       }
      
      
  5. Run database migrations:
    python manage.py makemigrations
    python manage.py migrate
    
  6. Run Redis (if not already running):
       redis-server.exe  # On Windows

image

  1. Run the Django development server:
       python manage.py runserver
    
  2. Create a superuser for the admin panel (optional):
       python manage.py createsuperuser
    

API Documentation

User Signup

  • URL:
    /api/users/signup/
  • Method: POST
  • Payload: { "email": "[email protected]", "password": "yourpassword" }
  • Response: User creation success message. image

User Login

  • URL:
    /api/users/login/
  • Method: POST
  • Payload: { "email": "[email protected]", "password": "yourpassword" }
  • Response: JWT access and refresh tokens. image

Send Friend Request

  • URL:
    /api/users/friend-request/send/<receiver_id>/
  • Method: POST
  • Response: Success or failure message. image

Respond to Friend Request

  • URL:
       /api/users/friend-request/respond/<request_id>/<action>/
  • Method: POST
  • Actions: Accept or Reject (accept, reject)
  • Response: Friend request status update message. image

View Friends List

  • 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) image

Search Users

  • URL:
       /api/users/search/
  • Method: GET
  • Query Param: search=
  • Response: List of users matching the search keyword. image

View User Activities

  • URL:
       /api/users/activity/
  • Method: GET
  • Response: List of user activities. image

User Logout

  • URL:
       /api/users/logout/
  • Method: POST image

Postman Collection

  • Download the Postman Collection

Containerization with Docker**

  • To containerize the application and run it using Docker, follow these steps:
  1. Ensure Docker is installed on your system: You can install Docker from here.

  2. Build the Docker image: docker-compose build

  3. 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.
  1. 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>
  1. 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

  2. Stop and remove the Docker containers: To stop the containers, run: docker-compose down

Requirements

  • Python 3.x
  • Django
  • Django REST Framework
  • djangorestframework-simplejwt
  • psycopg2
  • Redis
  • Docker

Dependencies:

  • All dependencies are listed in requirements.txt.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published