Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.DS_Store
.vscode/
4 changes: 4 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"python.defaultInterpreterPath": "backend/python/env/Scripts/python.exe",
"python.terminal.activateEnvironment": true
Comment thread
kajal-082 marked this conversation as resolved.
}
Binary file added RIPPLING/WEEK 2 RIPPLING.pdf
Binary file not shown.
3 changes: 3 additions & 0 deletions backend/python/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
__pycache__/
*.py[cod]
venv/
env/
backend/python/env/

*.env

.env
Expand Down
73 changes: 27 additions & 46 deletions backend/python/django_app/settings.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,31 @@
"""
Django settings for backend project.

Generated by 'django-admin startproject' using Django 6.0.2.

For more information on this file, see
https://docs.djangoproject.com/en/6.0/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/6.0/ref/settings/
"""

from dotenv import load_dotenv
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/6.0/howto/deployment/checklist/
load_dotenv()

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = "setup key"
BASE_DIR = Path(__file__).resolve().parent.parent

# SECURITY WARNING: don't run with debug turned on in production!
SECRET_KEY = os.getenv("SECRET_KEY", "fallback-key")
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [

"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"rest_framework",
"rest_framework.authtoken",
"product",
"product_csr",
]

MIDDLEWARE = [
"corsheaders.middleware.CorsMiddleware",
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
Expand Down Expand Up @@ -69,21 +55,13 @@

WSGI_APPLICATION = "django_app.wsgi.application"


# Database
# https://docs.djangoproject.com/en/6.0/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": BASE_DIR / "db.sqlite3",
}
}


# Password validation
# https://docs.djangoproject.com/en/6.0/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
Expand All @@ -99,25 +77,28 @@
},
]


# Internationalization
# https://docs.djangoproject.com/en/6.0/topics/i18n/

LANGUAGE_CODE = "en-us"

TIME_ZONE = "UTC"

USE_I18N = True

USE_TZ = True

STATIC_URL = "static/"
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/6.0/howto/static-files/
from mongoengine import connect

STATIC_URL = "static/"
connect(
db="product_db",
host="localhost",
port=27017,
)

# Default primary key field type
# https://docs.djangoproject.com/en/6.0/ref/settings/#default-auto-field
CORS_ALLOWED_ORIGINS = [
"http://localhost:3000",
]

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
REST_FRAMEWORK = {
"DEFAULT_AUTHENTICATION_CLASSES": [
"rest_framework.authentication.TokenAuthentication",
],
}
19 changes: 14 additions & 5 deletions backend/python/django_app/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
from django.contrib import admin
from django.urls import path
from django.http import HttpResponse
from django.urls import path , include
from django.http import JsonResponse

def hello_name(request):
"""
A simple view that returns 'Hello, {name}' in JSON format.
Uses a query parameter named 'name'.
"""
# Get 'name' from the query string, default to 'World' if missing
name = request.GET.get("name", "World")
return JsonResponse({"message": f"Hello, {name}!"})

def hello_world(request):
return HttpResponse("Hello, world! This is our interneers-lab Django server.")

urlpatterns = [
path('admin/', admin.site.urls),
path('hello/', hello_world),
path('hello/', hello_name),
path('product/',include('product.urls')) ,
path('product-csr/',include('product_csr.urls'))
]
7 changes: 4 additions & 3 deletions backend/python/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@

services:
mongodb:
image: mongo:8.0
image: mongo:6
container_name: interneers_lab_2026_mongodb
ports:
- '27019:27017'
environment:
MONGO_INITDB_ROOT_USERNAME: root
MONGO_INITDB_ROOT_PASSWORD: example
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin123
volumes:
- mongodb_data:/data/db

Expand Down
Empty file.
3 changes: 3 additions & 0 deletions backend/python/product/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
5 changes: 5 additions & 0 deletions backend/python/product/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.apps import AppConfig


class ProductConfig(AppConfig):
name = 'product'
5 changes: 5 additions & 0 deletions backend/python/product/data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# in memory storage
# all the data related to the product will be stored here on calling
# also all products will be stored onlly while server is running

products = []
Empty file.
14 changes: 14 additions & 0 deletions backend/python/product/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from django.db import models

# Create your models here.
# product model (no db becoz of in memory only)

class Product :
def __init__(self,id,name,desc,category,price,brand,quantity):
self.id = id
self.name = name
self.desc = desc
self.category = category
self.price = price
self.brand = brand
self.quantity = quantity
3 changes: 3 additions & 0 deletions backend/python/product/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
10 changes: 10 additions & 0 deletions backend/python/product/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from django.urls import path
from . import views


urlpatterns = [
path("products/",views.create_product),
path("products/<int:id>/",views.get_product),
path("products/<int:id>/update/",views.update_product),
path("products/<int:id>/delete/",views.delete_product),
]
88 changes: 88 additions & 0 deletions backend/python/product/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import json
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt
from .models import Product
from .data import products


@csrf_exempt
def create_product(request):
# GET → fetch all products
if request.method == "GET":
return JsonResponse({"products": products})

# POST → create product
if request.method == "POST":
data = json.loads(request.body)

required_fields = ["name", "price", "category", "brand", "quantity"]
for field in required_fields:
if field not in data:
return JsonResponse(
{"error": f"{field} is required"},
status=400
)

if data["price"] <= 0:
return JsonResponse(
{"error": "Price must be positive"},
status=400
)

product = Product(
id=len(products) + 1,
Comment thread
kajal-082 marked this conversation as resolved.
name=data["name"],
description=data.get("description", ""),
Comment thread
kajal-082 marked this conversation as resolved.
category=data["category"],
price=data["price"],
brand=data["brand"],
quantity=data["quantity"]
)

products.append(product.__dict__)
Comment thread
kajal-082 marked this conversation as resolved.

return JsonResponse(
{"message": "Product created", "product": product.__dict__},
status=201
)

return JsonResponse({"error": "Method not allowed"}, status=405)


@csrf_exempt
def get_product(request, id):
if request.method != "GET":
return JsonResponse({"error": "Method not allowed"}, status=405)

for product in products:
if product["id"] == id:
return JsonResponse(product)

return JsonResponse({"error": "Product not found"}, status=404)


@csrf_exempt
def update_product(request, id):
if request.method != "PUT":
return JsonResponse({"error": "Method not allowed"}, status=405)

data = json.loads(request.body)

for product in products:
if product["id"] == id:
product.update(data)
return JsonResponse(
{"message": "Product Updated", "product": product}
)

return JsonResponse({"error": "Product not found"}, status=404)


@csrf_exempt
def delete_product(request, id):
if request.method != "DELETE":
return JsonResponse({"error": "Method not allowed"}, status=405)

global products
products = [p for p in products if p["id"] != id]
return JsonResponse({"message": "Product deleted"})
Empty file.
3 changes: 3 additions & 0 deletions backend/python/product_csr/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions backend/python/product_csr/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class ProductCsrConfig(AppConfig):
name = "product_csr"

Loading