Skip to content

shaileshpadave/ipoTest

Repository files navigation

IPO Backend API

A Django REST API for managing IPO (Initial Public Offering) data with comprehensive filtering, search, and CRUD operations.

πŸš€ Quick Start

Prerequisites

  • Python 3.8 or higher
  • pip (Python package manager)

1. Setup Virtual Environment (Recommended)

python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

2. Install Dependencies

pip install -r requirements.txt

3. Environment Configuration

cp .env.example .env
# Edit .env file with your configuration

4. Run Setup Script

python setup_backend.py

5. Create Sample Data (Optional)

python create_sample_data.py

6. Start Development Server

python manage.py runserver

The API will be available at: http://127.0.0.1:8000/api/

πŸ“‹ API Endpoints

Main Endpoints

  • GET /api/ipo/ - List all IPOs (with filtering & search)
  • POST /api/ipo/ - Create new IPO
  • GET /api/ipo/{id}/ - Get IPO details
  • PUT /api/ipo/{id}/ - Update IPO
  • DELETE /api/ipo/{id}/ - Delete IPO

Special Endpoints

  • GET /api/ipo/upcoming/ - Get upcoming IPOs
  • GET /api/ipo/ongoing/ - Get ongoing IPOs
  • GET /api/ipo/listed/ - Get listed IPOs
  • GET /api/ipo/search/?q=term - Search IPOs
  • GET /api/ipo/stats/ - Get statistics

πŸ” Features

Filtering & Search

  • Filter by status, dates, price ranges
  • Search by company name and issue type
  • Sort by any field (ascending/descending)
  • Pagination support

Data Management

  • Complete CRUD operations
  • File uploads (logos, documents)
  • Automatic calculation of returns
  • Data validation

Admin Interface

  • Django admin at /admin/
  • Easy data management
  • Bulk operations

πŸ“Š Sample Usage

Get All IPOs

curl http://127.0.0.1:8000/api/ipo/

Get Upcoming IPOs

curl http://127.0.0.1:8000/api/ipo/upcoming/

Search IPOs

curl "http://127.0.0.1:8000/api/ipo/search/?q=tech"

Filter by Status and Date

curl "http://127.0.0.1:8000/api/ipo/?status=listed&open_date_from=2024-01-01"

Create New IPO

curl -X POST http://127.0.0.1:8000/api/ipo/ \
  -H "Content-Type: application/json" \
  -d '{
    "company_name": "New Tech Corp",
    "price_band": "β‚Ή200-250",
    "open_date": "2024-12-20",
    "close_date": "2024-12-23",
    "issue_size": "β‚Ή1000 Cr",
    "issue_type": "Fresh Issue",
    "status": "upcoming",
    "ipo_price": 225.0
  }'

πŸ“ Django Files Explained (For Beginners)

Main Project Files

manage.py               # πŸ”§ Django's command-line tool (run migrations, start server)
requirements.txt        # πŸ“¦ List of Python packages to install
.env                   # πŸ” Secret settings (passwords, keys) - don't share!

Project Directory (ipo_backend/)

ipo_backend/
β”œβ”€β”€ __init__.py        # πŸ“ Makes this a Python package (usually empty)
β”œβ”€β”€ settings.py        # βš™οΈ  Main configuration (database, apps, security)
β”œβ”€β”€ urls.py           # πŸ›£οΈ  Main URL routing (which URLs go where)
β”œβ”€β”€ wsgi.py           # 🌐 Web server configuration (for deployment)
└── asgi.py           # ⚑ Async server configuration (for real-time features)

App Directory (ipo_app/)

ipo_app/
β”œβ”€β”€ __init__.py        # πŸ“ Makes this a Python package
β”œβ”€β”€ models.py         # πŸ—ƒοΈ  Database structure (IPO data fields)
β”œβ”€β”€ views.py          # 🎯 Business logic (what happens when API is called)
β”œβ”€β”€ urls.py           # πŸ›£οΈ  App-specific URL routing
β”œβ”€β”€ serializers.py    # πŸ”„ Convert data between Python and JSON
β”œβ”€β”€ admin.py          # πŸ‘¨β€πŸ’Ό Django admin panel configuration
β”œβ”€β”€ apps.py           # πŸ“± App configuration
└── filters.py        # πŸ” Search and filter logic

Key Concepts

  • Models = Database tables (what data looks like)
  • Views = Controllers (what happens when someone visits URL)
  • URLs = Routes (which URL calls which view)
  • Serializers = Data formatters (Python ↔ JSON)
  • Admin = Built-in management interface

πŸ”„ How Django Works (Simple Flow)

1. User visits URL β†’ 2. urls.py finds matching view β†’ 3. views.py processes request
                                                          ↓
4. Response sent back ← 5. Serializer formats data ← 6. models.py gets data from database

Example: User visits /api/ipo/

  1. ipo_backend/urls.py β†’ routes to ipo_app/urls.py
  2. ipo_app/urls.py β†’ calls IPOViewSet in views.py
  3. views.py β†’ gets IPO data from models.py
  4. serializers.py β†’ converts data to JSON
  5. JSON response sent to user

πŸ› οΈ Development

Project Structure

ipo_backend/
β”œβ”€β”€ ipo_backend/          # Main Django project
β”‚   β”œβ”€β”€ settings.py      # Django settings
β”‚   β”œβ”€β”€ urls.py          # Main URL configuration
β”‚   └── ...
β”œβ”€β”€ ipo_app/             # IPO application
β”‚   β”œβ”€β”€ models.py        # Data models
β”‚   β”œβ”€β”€ serializers.py   # API serializers
β”‚   β”œβ”€β”€ views.py         # API views
β”‚   β”œβ”€β”€ urls.py          # App URLs
β”‚   β”œβ”€β”€ admin.py         # Admin configuration
β”‚   └── filters.py       # Custom filters
β”œβ”€β”€ manage.py            # Django management script
β”œβ”€β”€ requirements.txt     # Python dependencies
└── ...

Running Tests

python manage.py test

Django Commands Cheat Sheet

# Start development server
python manage.py runserver

# Create migrations (after changing models.py)
python manage.py makemigrations

# Apply migrations to database
python manage.py migrate

# Create admin user
python manage.py createsuperuser

# Open Django shell (interactive Python with Django)
python manage.py shell

# Check for issues
python manage.py check

# Collect static files (for production)
python manage.py collectstatic

Making Migrations

python manage.py test

Making Migrations

python manage.py makemigrations
python manage.py migrate

Creating Superuser

python manage.py createsuperuser

πŸ”§ Configuration

Environment Variables (.env)

SECRET_KEY=your-secret-key
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
CORS_ALLOWED_ORIGINS=http://localhost:3000,http://127.0.0.1:3000

Database

  • Default: SQLite (for development)
  • Production: PostgreSQL recommended

πŸ“š Documentation

🚒 Deployment

Production Checklist

  1. Set DEBUG=False
  2. Configure proper SECRET_KEY
  3. Set up PostgreSQL database
  4. Configure static file serving
  5. Set up proper CORS origins
  6. Use environment variables for sensitive data

Docker Deployment (Optional)

Create Dockerfile and docker-compose.yml for containerized deployment.

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License.


Happy coding! πŸŽ‰

About

Testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published