Skip to content

gaurav-dev02/GiddyComplexActivemovie

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Django Backend Developer Assignment

A Django REST API application with CRUD operations, background tasks using Celery, and comprehensive features.

Features

  • Models: Orders, Customer, Seller, Product, PlatformApiCall
  • Authentication: Token-based authentication
  • CRUD Operations: Full CRUD for Orders and Products using Django REST Framework
  • Permissions: Custom permissions and user restrictions
  • API Logging: Automatic logging of all API calls via mixin
  • Search & Filtering: Advanced search and filtering capabilities
  • Background Tasks: Celery integration with scheduled tasks
  • Excel Import: Management command to import products from Excel files
  • Data Validation: Duplicate prevention and data validation

Models

Customer

  • name, mobile, User (Foreign Key)

Seller

  • name, mobile, User (Foreign Key)

Product

  • name (unique), amount
  • Validation for duplicate product creation

Order

  • customer (FK), seller (FK), products (ManyToMany), amount

PlatformApiCall

  • User (FK), requested_url, requested_data, response_data

API Endpoints

Authentication

  • POST /api/auth/token/ - Get authentication token

Products

  • GET /api/products/ - List products (with search, filter, sorting)
  • POST /api/products/ - Create product
  • GET /api/products/{id}/ - Retrieve product
  • PUT /api/products/{id}/ - Update product
  • DELETE /api/products/{id}/ - Delete product

Orders

  • GET /api/orders/ - List orders (with product filter, search)
  • POST /api/orders/ - Create order
  • GET /api/orders/{id}/ - Retrieve order
  • PUT /api/orders/{id}/ - Update order
  • DELETE /api/orders/{id}/ - Delete order

Customer Orders (Restricted)

  • GET /api/my-orders/ - List customer's own orders only

Customers

  • GET /api/customers/ - List customers
  • POST /api/customers/ - Create customer

Sellers

  • GET /api/sellers/ - List sellers
  • POST /api/sellers/ - Create seller

Query Parameters

Filtering & Search

  • ?search=<term> - Search products by name in orders
  • ?products=<id> - Filter orders by product
  • ?ordering=asc|desc|top5 - Sort results

Examples

  • /api/orders/?search=laptop - Search orders containing "laptop"
  • /api/orders/?products=1 - Filter orders containing product ID 1
  • /api/products/?ordering=top5 - Get top 5 products by amount

Setup Instructions

1. Install Dependencies

pip install djangorestframework celery redis pandas openpyxl django-cors-headers

2. Database Setup

python manage.py makemigrations
python manage.py migrate

3. Create Superuser

python manage.py createsuperuser

4. Start Redis Server (for Celery)

redis-server

5. Start Django Development Server

python manage.py runserver 0.0.0.0:3000

6. Start Celery Worker (in new terminal)

celery -A django_project worker --loglevel=info

7. Start Celery Beat (for scheduled tasks)

celery -A django_project beat --loglevel=info

Authentication

  1. Create user account through Django admin or API
  2. Get token: POST /api/auth/token/ with username/password
  3. Include token in headers: Authorization: Token <your-token>

Import Products from Excel

Using Management Command

python manage.py import_products path/to/your/file.xlsx

Excel File Format

  • Column A: name (Product name)
  • Column B: amount (Product amount)

Using Celery Task

The system automatically runs import task daily at 2:30 PM. You can also trigger manually:

from api.tasks import import_products_task
import_products_task.delay('path/to/file.xlsx')

Features Implementation

1. Token Authentication

  • Implemented using DRF TokenAuthentication
  • Required for all API endpoints

2. CRUD Operations

  • Full CRUD for Orders and Products
  • Proper serializers with validation

3. PlatformApiCall Mixin

  • Automatically logs all API calls
  • Captures request data, response data, and metadata

4. Permissions

  • Customer-only decorator for restricted endpoints
  • Custom permissions for object-level access

5. Advanced Querying

  • select_related: Used for Order list APIs to optimize user queries
  • prefetch_related: Used for Product search in Order queries
  • Search and filtering capabilities

6. Duplicate Prevention

  • Product model validates unique names (case-insensitive)
  • Excel import skips duplicates

7. Sorting Options

  • Ascending/Descending order
  • Top 5 results option

8. Customer Restrictions

  • Customers can only view their own orders
  • Decorator-based access control

Deployment on Replit

  1. The application is configured to run on 0.0.0.0:3000
  2. CORS is configured for cross-origin requests
  3. Static and media files are properly configured
  4. Database uses SQLite for simplicity

Celery Configuration

  • Broker: Redis
  • Scheduled Task: Daily at 2:30 PM for product import
  • Tasks: Product import from Excel files

Testing

Access the API using tools like:

  • Django admin panel: /admin/
  • DRF browsable API: /api/
  • Postman or curl for API testing

Security Features

  • Token-based authentication
  • CSRF protection
  • User permission validation
  • Input data validation
  • SQL injection prevention through Django ORM

Performance Optimizations

  • Database query optimization with select_related and prefetch_related
  • Pagination for large datasets
  • Efficient filtering and search implementation

Releases

No releases published

Packages

No packages published

Languages