-
Notifications
You must be signed in to change notification settings - Fork 92
Implement product_csr app #74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
kajal-082
wants to merge
19
commits into
Rippling:main
Choose a base branch
from
kajal-082:kajal-new-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8ddfbc8
first api call
kajal-082 ed4f5e2
modify settings.py file
kajal-082 6f1d532
Remove .env.txt from repo
kajal-082 b00fef8
Update .gitignore to ignore env folders
kajal-082 9f27f41
Added product app
kajal-082 8e189f0
created product using csr archi
b0d1ecd
Author correction commit
9f2bfe5
added categoreies functionality
kajal-082 c14c70f
added seed scripts to instantiate product categories on server startup
kajal-082 e1d7a9f
setting rich filters to fetch list of categories
kajal-082 b9162b1
added testfile for product_service and category_service
kajal-082 8ef7341
completed till week 5
kajal-082 d9ff9a4
added basic frontend (included basic html/css/js
kajal-082 597614c
final changes done of week 6
kajal-082 19150d9
added react components and done with week 7 work
kajal-082 02e8fc9
added dedicated productpage
kajal-082 d865a00
added product category page and done with week 8
kajal-082 ae7e5c5
final changes
kajal-082 475bf0b
added authentication and final touchup
kajal-082 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,2 @@ | ||
| .DS_Store | ||
| .vscode/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| } | ||
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,9 @@ | ||
| __pycache__/ | ||
| *.py[cod] | ||
| venv/ | ||
| env/ | ||
| backend/python/env/ | ||
|
|
||
| *.env | ||
|
|
||
| .env | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')) | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from django.apps import AppConfig | ||
|
|
||
|
|
||
| class ProductConfig(AppConfig): | ||
| name = 'product' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.test import TestCase | ||
|
|
||
| # Create your tests here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
|
kajal-082 marked this conversation as resolved.
|
||
| name=data["name"], | ||
| description=data.get("description", ""), | ||
|
kajal-082 marked this conversation as resolved.
|
||
| category=data["category"], | ||
| price=data["price"], | ||
| brand=data["brand"], | ||
| quantity=data["quantity"] | ||
| ) | ||
|
|
||
| products.append(product.__dict__) | ||
|
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from django.contrib import admin | ||
|
|
||
| # Register your models here. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.