From 49c8fe1f9f7a6957fcc15d0ec2e2d7514132bf15 Mon Sep 17 00:00:00 2001 From: coderj001 Date: Mon, 5 Apr 2021 10:38:34 +0530 Subject: [PATCH] setup backend django server --- .gitignore | 2 + backend/Backend/__init__.py | 0 backend/Backend/asgi.py | 16 ++++ backend/Backend/settings.py | 92 +++++++++++++++++++ backend/Backend/urls.py | 6 ++ backend/Backend/wsgi.py | 16 ++++ backend/Pipfile | 16 ++++ backend/Pipfile.lock | 137 ++++++++++++++++++++++++++++ backend/core/__init__.py | 0 backend/core/admin.py | 3 + backend/core/apps.py | 5 + backend/core/migrations/__init__.py | 0 backend/core/models.py | 3 + backend/core/tests.py | 3 + backend/core/urls.py | 7 ++ backend/core/views.py | 3 + backend/manage.py | 22 +++++ frontend/src/Pages/ProductPage.jsx | 94 ++++++++++++++++++- frontend/src/components/Navbar.jsx | 24 +++-- 19 files changed, 437 insertions(+), 12 deletions(-) create mode 100644 backend/Backend/__init__.py create mode 100644 backend/Backend/asgi.py create mode 100644 backend/Backend/settings.py create mode 100644 backend/Backend/urls.py create mode 100644 backend/Backend/wsgi.py create mode 100644 backend/Pipfile create mode 100644 backend/Pipfile.lock create mode 100644 backend/core/__init__.py create mode 100644 backend/core/admin.py create mode 100644 backend/core/apps.py create mode 100644 backend/core/migrations/__init__.py create mode 100644 backend/core/models.py create mode 100644 backend/core/tests.py create mode 100644 backend/core/urls.py create mode 100644 backend/core/views.py create mode 100755 backend/manage.py diff --git a/.gitignore b/.gitignore index 24ca2b9..4b8b872 100644 --- a/.gitignore +++ b/.gitignore @@ -182,3 +182,5 @@ sketch # End of https://www.toptal.com/developers/gitignore/api/react tags +.env +.vim/ diff --git a/backend/Backend/__init__.py b/backend/Backend/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/Backend/asgi.py b/backend/Backend/asgi.py new file mode 100644 index 0000000..1513a5e --- /dev/null +++ b/backend/Backend/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for Backend project. + +It exposes the ASGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Backend.settings') + +application = get_asgi_application() diff --git a/backend/Backend/settings.py b/backend/Backend/settings.py new file mode 100644 index 0000000..f29b45f --- /dev/null +++ b/backend/Backend/settings.py @@ -0,0 +1,92 @@ +from pathlib import Path +import os + +BASE_DIR = Path(__file__).resolve().parent.parent + +SECRET_KEY = os.environ.get('secret_key') + +DEBUG = True + +ALLOWED_HOSTS = [] + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + 'core.apps.CoreConfig' +] + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +] + +ROOT_URLCONF = 'Backend.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +WSGI_APPLICATION = 'Backend.wsgi.application' + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': + 'django.contrib.auth.password_validation.' + + 'UserAttributeSimilarityValidator', + }, + { + 'NAME': + 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': + 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': + 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +STATIC_URL = '/static/' diff --git a/backend/Backend/urls.py b/backend/Backend/urls.py new file mode 100644 index 0000000..dfc7362 --- /dev/null +++ b/backend/Backend/urls.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from django.urls import path + +urlpatterns = [ + path('admin/', admin.site.urls), +] diff --git a/backend/Backend/wsgi.py b/backend/Backend/wsgi.py new file mode 100644 index 0000000..091dc2b --- /dev/null +++ b/backend/Backend/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for Backend project. + +It exposes the WSGI callable as a module-level variable named ``application``. + +For more information on this file, see +https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Backend.settings') + +application = get_wsgi_application() diff --git a/backend/Pipfile b/backend/Pipfile new file mode 100644 index 0000000..9c120f8 --- /dev/null +++ b/backend/Pipfile @@ -0,0 +1,16 @@ +[[source]] +url = "https://pypi.python.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +django = "*" +djangorestframework = "*" + +[dev-packages] +django-linter = "*" +pylint = "*" +isort = "*" + +[requires] +python_version = "3.8" diff --git a/backend/Pipfile.lock b/backend/Pipfile.lock new file mode 100644 index 0000000..746f385 --- /dev/null +++ b/backend/Pipfile.lock @@ -0,0 +1,137 @@ +{ + "_meta": { + "hash": { + "sha256": "377b77fb420170a5e31c259fd660d3597320ee8dad5190417437445b83f99fa3" + }, + "pipfile-spec": 6, + "requires": { + "python_version": "3.8" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.python.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "asgiref": { + "hashes": [ + "sha256:5ee950735509d04eb673bd7f7120f8fa1c9e2df495394992c73234d526907e17", + "sha256:7162a3cb30ab0609f1a4c95938fd73e8604f63bdba516a7f7d64b83ff09478f0" + ], + "version": "==3.3.1" + }, + "django": { + "hashes": [ + "sha256:32ce792ee9b6a0cbbec340123e229ac9f765dff8c2a4ae9247a14b2ba3a365a7", + "sha256:baf099db36ad31f970775d0be5587cc58a6256a6771a44eb795b554d45f211b8" + ], + "index": "pypi", + "version": "==3.1.7" + }, + "djangorestframework": { + "hashes": [ + "sha256:6d1d59f623a5ad0509fe0d6bfe93cbdfe17b8116ebc8eda86d45f6e16e819aaf", + "sha256:f747949a8ddac876e879190df194b925c177cdeb725a099db1460872f7c0a7f2" + ], + "index": "pypi", + "version": "==3.12.4" + }, + "pytz": { + "hashes": [ + "sha256:83a4a90894bf38e243cf052c8b58f381bfe9a7a483f6a9cab140bc7f702ac4da", + "sha256:eb10ce3e7736052ed3623d49975ce333bcd712c7bb19a58b9e2089d4057d0798" + ], + "version": "==2021.1" + }, + "sqlparse": { + "hashes": [ + "sha256:017cde379adbd6a1f15a61873f43e8274179378e95ef3fede90b5aa64d304ed0", + "sha256:0f91fd2e829c44362cbcfab3e9ae12e22badaa8a29ad5ff599f9ec109f0454e8" + ], + "version": "==0.4.1" + } + }, + "develop": { + "astroid": { + "hashes": [ + "sha256:6b0ed1af831570e500e2437625979eaa3b36011f66ddfc4ce930128610258ca9", + "sha256:cd80bf957c49765dce6d92c43163ff9d2abc43132ce64d4b1b47717c6d2522df" + ], + "version": "==2.5.2" + }, + "colorama": { + "hashes": [ + "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b", + "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2" + ], + "version": "==0.4.4" + }, + "django-linter": { + "hashes": [ + "sha256:543bfe9f8eb11d3ff56fc6575864dd7dad8af60cd4eab0ecf6b1def220d52c87", + "sha256:60b7b31ac84a806744607751cb925504060b6b211c42bd9e35bd7047505e70e4" + ], + "index": "pypi", + "version": "==0.7" + }, + "isort": { + "hashes": [ + "sha256:0a943902919f65c5684ac4e0154b1ad4fac6dcaa5d9f3426b732f1c8b5419be6", + "sha256:2bb1680aad211e3c9944dbce1d4ba09a989f04e238296c87fe2139faa26d655d" + ], + "index": "pypi", + "version": "==5.8.0" + }, + "lazy-object-proxy": { + "hashes": [ + "sha256:17e0967ba374fc24141738c69736da90e94419338fd4c7c7bef01ee26b339653", + "sha256:1fee665d2638491f4d6e55bd483e15ef21f6c8c2095f235fef72601021e64f61", + "sha256:22ddd618cefe54305df49e4c069fa65715be4ad0e78e8d252a33debf00f6ede2", + "sha256:24a5045889cc2729033b3e604d496c2b6f588c754f7a62027ad4437a7ecc4837", + "sha256:410283732af311b51b837894fa2f24f2c0039aa7f220135192b38fcc42bd43d3", + "sha256:4732c765372bd78a2d6b2150a6e99d00a78ec963375f236979c0626b97ed8e43", + "sha256:489000d368377571c6f982fba6497f2aa13c6d1facc40660963da62f5c379726", + "sha256:4f60460e9f1eb632584c9685bccea152f4ac2130e299784dbaf9fae9f49891b3", + "sha256:5743a5ab42ae40caa8421b320ebf3a998f89c85cdc8376d6b2e00bd12bd1b587", + "sha256:85fb7608121fd5621cc4377a8961d0b32ccf84a7285b4f1d21988b2eae2868e8", + "sha256:9698110e36e2df951c7c36b6729e96429c9c32b3331989ef19976592c5f3c77a", + "sha256:9d397bf41caad3f489e10774667310d73cb9c4258e9aed94b9ec734b34b495fd", + "sha256:b579f8acbf2bdd9ea200b1d5dea36abd93cabf56cf626ab9c744a432e15c815f", + "sha256:b865b01a2e7f96db0c5d12cfea590f98d8c5ba64ad222300d93ce6ff9138bcad", + "sha256:bf34e368e8dd976423396555078def5cfc3039ebc6fc06d1ae2c5a65eebbcde4", + "sha256:c6938967f8528b3668622a9ed3b31d145fab161a32f5891ea7b84f6b790be05b", + "sha256:d1c2676e3d840852a2de7c7d5d76407c772927addff8d742b9808fe0afccebdf", + "sha256:d7124f52f3bd259f510651450e18e0fd081ed82f3c08541dffc7b94b883aa981", + "sha256:d900d949b707778696fdf01036f58c9876a0d8bfe116e8d220cfd4b15f14e741", + "sha256:ebfd274dcd5133e0afae738e6d9da4323c3eb021b3e13052d8cbd0e457b1256e", + "sha256:ed361bb83436f117f9917d282a456f9e5009ea12fd6de8742d1a4752c3017e93", + "sha256:f5144c75445ae3ca2057faac03fda5a902eff196702b0a24daf1d6ce0650514b" + ], + "version": "==1.6.0" + }, + "pylint": { + "hashes": [ + "sha256:044e9f03eee51ac1cb05f094af6ccc2a2195c558d233819c22527062dff46225", + "sha256:b7c01613c9c00fbf4dc359714b5f7867612df27eca9dddf571c0bc2db8e13a39" + ], + "index": "pypi", + "version": "==1.5.1" + }, + "six": { + "hashes": [ + "sha256:30639c035cdb23534cd4aa2dd52c3bf48f06e5f4a941509c8bafd8ce11080259", + "sha256:8b74bedcbbbaca38ff6d7491d76f2b06b3592611af620f8426e82dddb04a5ced" + ], + "version": "==1.15.0" + }, + "wrapt": { + "hashes": [ + "sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7" + ], + "version": "==1.12.1" + } + } +} diff --git a/backend/core/__init__.py b/backend/core/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/core/admin.py b/backend/core/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/backend/core/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/backend/core/apps.py b/backend/core/apps.py new file mode 100644 index 0000000..26f78a8 --- /dev/null +++ b/backend/core/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CoreConfig(AppConfig): + name = 'core' diff --git a/backend/core/migrations/__init__.py b/backend/core/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/backend/core/models.py b/backend/core/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/backend/core/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/backend/core/tests.py b/backend/core/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/backend/core/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/backend/core/urls.py b/backend/core/urls.py new file mode 100644 index 0000000..86f775c --- /dev/null +++ b/backend/core/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +APP_NAME = 'core' + +urlpatterns = [ + path(), +] diff --git a/backend/core/views.py b/backend/core/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/backend/core/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/backend/manage.py b/backend/manage.py new file mode 100755 index 0000000..05e0b12 --- /dev/null +++ b/backend/manage.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python +"""Django's command-line utility for administrative tasks.""" +import os +import sys + + +def main(): + """Run administrative tasks.""" + os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'Backend.settings') + try: + from django.core.management import execute_from_command_line + except ImportError as exc: + raise ImportError( + "Couldn't import Django. Are you sure it's installed and " + "available on your PYTHONPATH environment variable? Did you " + "forget to activate a virtual environment?" + ) from exc + execute_from_command_line(sys.argv) + + +if __name__ == '__main__': + main() diff --git a/frontend/src/Pages/ProductPage.jsx b/frontend/src/Pages/ProductPage.jsx index 9038dd3..988d3a1 100644 --- a/frontend/src/Pages/ProductPage.jsx +++ b/frontend/src/Pages/ProductPage.jsx @@ -1,7 +1,97 @@ import React from "react"; +import { LinkContainer } from "react-router-bootstrap"; +import { + Container, + Row, + Col, + Image, + ListGroup, + Button, + Card, + Badge, +} from "react-bootstrap"; +import products from "../fakedata/products.json"; +import Rating from "../components/Rating"; -function ProductPage() { - return
Product
; +function ProductPage(props) { + const product = products.find((p) => p._id === props.match.params.id); + + return ( + + + + +
+
+ + + + {product.name} + + + + +

{product.name}

+
+ + + + + Price: Rs. {product.price} + + + Description: {product.description} + +
+ + + + + + + Price: + + ${product.price} + + + + + + Status: + + {product.countInStock > 0 ? ( + + {" "} + Available{" "} + + ) : ( + + {" "} + Not Available{" "} + + )} + + + + + + + + + +
+
+ ); } export default ProductPage; diff --git a/frontend/src/components/Navbar.jsx b/frontend/src/components/Navbar.jsx index f397651..e39c799 100644 --- a/frontend/src/components/Navbar.jsx +++ b/frontend/src/components/Navbar.jsx @@ -2,26 +2,30 @@ import React from "react"; import { Navbar, Nav, Container } from "react-bootstrap"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faShoppingCart, faSignInAlt } from "@fortawesome/free-solid-svg-icons"; -import { Link } from "react-router-dom"; +import { LinkContainer } from "react-router-bootstrap"; function Navigaton() { return (
- + ProShop - +