├── README.md ├── backend ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ ├── settings.cpython-310.pyc │ ├── urls.cpython-310.pyc │ └── wsgi.cpython-310.pyc ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── build_files.sh ├── db.sqlite3 ├── manage.py ├── media └── products │ └── CHatGPT_19.png ├── onlineshop ├── __init__.py ├── __pycache__ │ ├── __init__.cpython-310.pyc │ ├── admin.cpython-310.pyc │ ├── apps.cpython-310.pyc │ ├── models.cpython-310.pyc │ ├── serializers.cpython-310.pyc │ ├── urls.cpython-310.pyc │ └── views.cpython-310.pyc ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── __init__.py │ └── __pycache__ │ │ ├── 0001_initial.cpython-310.pyc │ │ └── __init__.cpython-310.pyc ├── models.py ├── serializers.py ├── tests.py ├── urls.py └── views.py ├── products └── IMG_6922.JPG ├── requirements.txt └── vercel.json /README.md: -------------------------------------------------------------------------------- 1 | # Become a Backend Developer in 3 Hours - Beginner To Advanced 2 | ![1i (2)](https://github.com/codewithmuh/backend_course/assets/51082957/c0e965ac-f871-41d7-a94e-d90cc3338db2) 3 | 4 | 5 | ## Overview 6 | 7 | Watch this tutorial to get started! 💻 8 | ## Udemy Url: udemy.com/course/learn-backend-development-with-python-django-and-aws/ 9 | I'll show you how to become a backend developer using Django, Django Rest Framework, email notification, Git, Postman, Vercel, AWS RDS PostgreSQL, AWS EC2 with Nginx and Gunicorn, and SSL and domain setup. 10 | ## Getting Started 11 | 12 | To get started with the Django Starter Kit: 13 | 14 | 1. **Clone the Repository**: `git clone https://github.com/codewithmuh/backend_course.git` 15 | ``` 16 | 17 | ## Contribution Guidelines 18 | 19 | Contributions to the Django Starter Kit are highly encouraged! Follow these guidelines to contribute: 20 | ### Note: Make sure the Docker desktop is installed and running on your system. You can download it from the official website of dockerhub. 21 | 22 | 1. Fork the repository. 23 | 2. Create a new branch: `git checkout -b feature/your-feature`. 24 | 3. Make your changes and commit them: `git commit -m 'Add your feature'`. 25 | 4. Push to the branch: `git push origin feature/your-feature`. 26 | 5. Submit a pull request! 27 | 28 | ## License 29 | This project is licensed under MIT License, granting you the freedom to use, modify, and distribute the code. 30 | 31 | ## Acknowledgements 32 | Special thanks to codewithmuh for creating this incredible Django Starter Kit and simplifying the development process. 33 | 34 | ## Support 35 | Buy Me A Coffee 36 | 37 | -------------------------------------------------------------------------------- /backend/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/backend/__init__.py -------------------------------------------------------------------------------- /backend/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/backend/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /backend/__pycache__/settings.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/backend/__pycache__/settings.cpython-310.pyc -------------------------------------------------------------------------------- /backend/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/backend/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /backend/__pycache__/wsgi.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/backend/__pycache__/wsgi.cpython-310.pyc -------------------------------------------------------------------------------- /backend/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for backend project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /backend/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for backend project. 3 | 4 | Generated by 'django-admin startproject' using Django 4.0.5. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/4.0/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | import os 15 | 16 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 17 | BASE_DIR = Path(__file__).resolve().parent.parent 18 | 19 | 20 | # Quick-start development settings - unsuitable for production 21 | # See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/ 22 | 23 | # SECURITY WARNING: keep the secret key used in production secret! 24 | SECRET_KEY = 'django-insecure-!1(h2&qu!f_(fdw7ddy&$y3sr=cq02ssh%d2%p0#17-%44a%#f' 25 | 26 | # SECURITY WARNING: don't run with debug turned on in production! 27 | DEBUG = True 28 | 29 | ALLOWED_HOSTS = ['*'] 30 | 31 | 32 | # Application definition 33 | 34 | INSTALLED_APPS = [ 35 | 'django.contrib.admin', 36 | 'django.contrib.auth', 37 | 'django.contrib.contenttypes', 38 | 'whitenoise.runserver_nostatic', 39 | 'django.contrib.sessions', 40 | 'django.contrib.messages', 41 | 'django.contrib.staticfiles', 42 | 'onlineshop', 43 | 'rest_framework', 44 | 'drf_yasg', 45 | 46 | 47 | ] 48 | 49 | MIDDLEWARE = [ 50 | 'django.middleware.security.SecurityMiddleware', 51 | 'django.contrib.sessions.middleware.SessionMiddleware', 52 | 'whitenoise.middleware.WhiteNoiseMiddleware', 53 | 'django.middleware.common.CommonMiddleware', 54 | 'django.middleware.csrf.CsrfViewMiddleware', 55 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 56 | 'django.contrib.messages.middleware.MessageMiddleware', 57 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 58 | ] 59 | 60 | ROOT_URLCONF = 'backend.urls' 61 | 62 | TEMPLATES = [ 63 | { 64 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 65 | 'DIRS': [], 66 | 'APP_DIRS': True, 67 | 'OPTIONS': { 68 | 'context_processors': [ 69 | 'django.template.context_processors.debug', 70 | 'django.template.context_processors.request', 71 | 'django.contrib.auth.context_processors.auth', 72 | 'django.contrib.messages.context_processors.messages', 73 | ], 74 | }, 75 | }, 76 | ] 77 | 78 | WSGI_APPLICATION = 'backend.wsgi.application' 79 | 80 | 81 | # Database 82 | # https://docs.djangoproject.com/en/4.0/ref/settings/#databases 83 | 84 | 85 | #Replace name, Password, Host with your RDS Database name, user, password, host. 86 | 87 | DATABASES = { 88 | 'default': { 89 | 'ENGINE': 'django.db.backends.postgresql', 90 | 'NAME': 'mydatabase', 91 | 'USER': 'mydatabaseuser', 92 | 'PASSWORD': 'mypassword', 93 | 'HOST': 'myrdshost.rds.amazonaws.com', 94 | 'PORT': '5432', 95 | } 96 | } 97 | 98 | 99 | # Password validation 100 | # https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators 101 | 102 | AUTH_PASSWORD_VALIDATORS = [ 103 | { 104 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 105 | }, 106 | { 107 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 108 | }, 109 | { 110 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 111 | }, 112 | { 113 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 114 | }, 115 | ] 116 | 117 | 118 | # Internationalization 119 | # https://docs.djangoproject.com/en/4.0/topics/i18n/ 120 | 121 | LANGUAGE_CODE = 'en-us' 122 | 123 | TIME_ZONE = 'UTC' 124 | 125 | USE_I18N = True 126 | 127 | USE_TZ = True 128 | 129 | 130 | # Static files (CSS, JavaScript, Images) 131 | # https://docs.djangoproject.com/en/4.0/howto/static-files/ 132 | 133 | STATIC_URL = 'static/' 134 | STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles_build', 'static') 135 | MEDIA_URLS ='/media/' 136 | MEDIA_ROOT = os.path.join(BASE_DIR, 'media') 137 | 138 | # Default primary key field type 139 | # https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field 140 | 141 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 142 | 143 | 144 | EMAIL_BACKEND ='django.core.mail.backends.smtp.EmailBackend' 145 | EMAIL_HOST = 'smtp.gmail.com' 146 | EMAIL_PORT = 587 147 | EMAIL_HOST_USER = 'Your Email' 148 | EMAIL_HOST_PASSWORD = 'Your Password' 149 | EMAIL_USE_TLS = True 150 | EMAIL_USE_SSL = False 151 | 152 | 153 | AWS_ACCESS_KEY_ID = 'AWS_ACCESS_KEY_ID ' 154 | AWS_SECRET_ACCESS_KEY = 'AWS_SECRET_ACCESS_KEY' 155 | AWS_STORAGE_BUCKET_NAME = 'AWS_STORAGE_BUCKET_NAME' 156 | AWS_S3_SIGNATURE_NAME = 's3v4', 157 | AWS_S3_REGION_NAME = 'AWS_S3_REGION_NAME' 158 | AWS_S3_FILE_OVERWRITE = False 159 | AWS_DEFAULT_ACL = None 160 | AWS_S3_VERIFY = True 161 | DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage' 162 | -------------------------------------------------------------------------------- /backend/urls.py: -------------------------------------------------------------------------------- 1 | """backend URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/4.0/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path, include 18 | from drf_yasg.views import get_schema_view 19 | from drf_yasg import openapi 20 | from django.conf import settings # new 21 | from django.conf.urls.static import static #new 22 | 23 | schema_view = get_schema_view( 24 | openapi.Info( 25 | title="Backend Online Shop APIS", 26 | default_version='1.0.0', 27 | description="This is swagger for our apis." 28 | 29 | ), 30 | public=True, 31 | ) 32 | 33 | 34 | urlpatterns = [ 35 | path('admin/', admin.site.urls), 36 | path('', include('onlineshop.urls')), 37 | path('swagger/schema/', schema_view.with_ui('swagger', cache_timeout=0), name='swagger-schema'), 38 | 39 | ] 40 | if settings.DEBUG: 41 | urlpatterns += static(settings.MEDIA_URL, document_root = settings.MEDIA_ROOT) 42 | urlpatterns += static(settings.STATIC_URL, document_root = settings.STATIC_URL) 43 | -------------------------------------------------------------------------------- /backend/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for backend project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') 15 | 16 | application = get_wsgi_application() 17 | 18 | app = application 19 | -------------------------------------------------------------------------------- /build_files.sh: -------------------------------------------------------------------------------- 1 | echo "BUILD START" 2 | python3.9 -m pip install -r requirements.txt 3 | python3.9 manage.py collectstatic --noinput --clear 4 | echo "BUILD END" -------------------------------------------------------------------------------- /db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/db.sqlite3 -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /media/products/CHatGPT_19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/media/products/CHatGPT_19.png -------------------------------------------------------------------------------- /onlineshop/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__init__.py -------------------------------------------------------------------------------- /onlineshop/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/__pycache__/admin.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__pycache__/admin.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/__pycache__/apps.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__pycache__/apps.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/__pycache__/models.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__pycache__/models.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/__pycache__/serializers.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__pycache__/serializers.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/__pycache__/urls.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__pycache__/urls.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/__pycache__/views.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/__pycache__/views.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Category, Product, order 4 | 5 | # Register your models here. 6 | 7 | @admin.register(Category) 8 | class CategoryAdmin(admin.ModelAdmin): 9 | list_display = ['category_name','description', 'created_at', 'updated_at'] 10 | 11 | 12 | 13 | @admin.register(Product) 14 | class ProductAdmin(admin.ModelAdmin): 15 | list_display = ['product_name','description', 'price', 'image', 'category', 'created_at', 'updated_at'] 16 | 17 | 18 | 19 | @admin.register(order) 20 | class OrderAdmin(admin.ModelAdmin): 21 | list_display = ['customer_name','customer_email', 'product', 'quantity','created_at', 'updated_at'] 22 | -------------------------------------------------------------------------------- /onlineshop/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class OnlineshopConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'onlineshop' 7 | -------------------------------------------------------------------------------- /onlineshop/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 4.1.6 on 2023-02-11 08:08 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Category', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('created_at', models.DateTimeField(auto_now_add=True)), 20 | ('updated_at', models.DateTimeField(auto_now=True)), 21 | ('category_name', models.CharField(max_length=180)), 22 | ('description', models.TextField(max_length=250)), 23 | ], 24 | options={ 25 | 'abstract': False, 26 | }, 27 | ), 28 | migrations.CreateModel( 29 | name='Product', 30 | fields=[ 31 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 32 | ('created_at', models.DateTimeField(auto_now_add=True)), 33 | ('updated_at', models.DateTimeField(auto_now=True)), 34 | ('product_name', models.CharField(max_length=180)), 35 | ('description', models.TextField(max_length=180)), 36 | ('price', models.DecimalField(decimal_places=2, max_digits=10)), 37 | ('image', models.FileField(upload_to='products/')), 38 | ('category', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='onlineshop.category')), 39 | ], 40 | options={ 41 | 'abstract': False, 42 | }, 43 | ), 44 | migrations.CreateModel( 45 | name='order', 46 | fields=[ 47 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 48 | ('created_at', models.DateTimeField(auto_now_add=True)), 49 | ('updated_at', models.DateTimeField(auto_now=True)), 50 | ('customer_name', models.CharField(max_length=180)), 51 | ('customer_email', models.EmailField(max_length=254)), 52 | ('quantity', models.PositiveIntegerField()), 53 | ('product', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='onlineshop.product')), 54 | ], 55 | options={ 56 | 'abstract': False, 57 | }, 58 | ), 59 | ] 60 | -------------------------------------------------------------------------------- /onlineshop/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/migrations/__init__.py -------------------------------------------------------------------------------- /onlineshop/migrations/__pycache__/0001_initial.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/migrations/__pycache__/0001_initial.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/migrations/__pycache__/__init__.cpython-310.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/onlineshop/migrations/__pycache__/__init__.cpython-310.pyc -------------------------------------------------------------------------------- /onlineshop/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | 5 | class TimestampModel(models.Model): 6 | created_at = models.DateTimeField(auto_now_add =True) 7 | updated_at = models.DateTimeField(auto_now =True) 8 | 9 | class Meta: 10 | abstract = True 11 | 12 | class Category(TimestampModel): 13 | category_name = models.CharField(max_length = 180) 14 | description = models.TextField(max_length = 250) 15 | 16 | def __str__(self): 17 | return self.category_name 18 | 19 | class Product(TimestampModel): 20 | product_name = models.CharField(max_length=180) 21 | description = models.TextField(max_length=180) 22 | price = models.DecimalField(max_digits =10, decimal_places=2) 23 | image = models.FileField(upload_to='products/') 24 | category = models.ForeignKey(Category, on_delete=models.CASCADE) 25 | 26 | def __str__(self): 27 | return self.product_name 28 | 29 | class order(TimestampModel): 30 | customer_name = models.CharField(max_length=180) 31 | customer_email = models.EmailField() 32 | product = models.ForeignKey(Product, on_delete=models.CASCADE) 33 | quantity = models.PositiveIntegerField() 34 | 35 | def __str__(self): 36 | return f"Order #1" 37 | -------------------------------------------------------------------------------- /onlineshop/serializers.py: -------------------------------------------------------------------------------- 1 | 2 | from rest_framework import serializers 3 | from .models import order 4 | 5 | 6 | class OrderSerializer(serializers.ModelSerializer): 7 | 8 | class Meta: 9 | model = order 10 | fields = '__all__' -------------------------------------------------------------------------------- /onlineshop/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /onlineshop/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from onlineshop.views import OrderView 3 | 4 | urlpatterns = [ 5 | 6 | path('order/', OrderView.as_view(), name='order'), 7 | ] 8 | 9 | 10 | -------------------------------------------------------------------------------- /onlineshop/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | from .models import order 4 | from .serializers import OrderSerializer 5 | 6 | from rest_framework.views import APIView 7 | from rest_framework import status 8 | from rest_framework.response import Response 9 | 10 | from django.core.mail import send_mail 11 | from backend.settings import EMAIL_HOST_USER 12 | 13 | 14 | # Create your views here. 15 | 16 | class OrderView(APIView): 17 | def get(self, request): 18 | try: 19 | orders = order.objects.all() 20 | serializer = OrderSerializer(orders, many=True) 21 | 22 | return Response({ 23 | 'data': serializer.data, 24 | 'message': "Orders Data fetched Successfully" 25 | }, status= status.HTTP_200_OK) 26 | 27 | except Exception as e: 28 | print(e) 29 | return Response({ 30 | 'data': {}, 31 | 'message': "Something went wrong while fetching the data" 32 | }, status= status.HTTP_400_BAD_REQUEST) 33 | 34 | def post(self, request): 35 | try: 36 | data = request.data 37 | serializer = OrderSerializer(data=data) 38 | 39 | if not serializer.is_valid(): 40 | return Response({ 41 | 'data': serializer.errors, 42 | 'message': "Something went wrong" 43 | }, status= status.HTTP_400_BAD_REQUEST) 44 | 45 | subject = "New Order is Placed" 46 | message = "Dear Customer" + " " + data['customer_name'] + " Your order is placed now. Thanks for your order" 47 | email = data['customer_email'] 48 | recipient_list = [email] 49 | send_mail(subject, message, EMAIL_HOST_USER, recipient_list, fail_silently=True) 50 | serializer.save() 51 | 52 | return Response({ 53 | 'data': serializer.data, 54 | 'message': "New order is created or Placed" 55 | }, status= status.HTTP_201_CREATED) 56 | 57 | except: 58 | return Response({ 59 | 'date': {}, 60 | 'message': "Something went wrong in creation of Order" 61 | }, status= status.HTTP_400_BAD_REQUEST) 62 | 63 | 64 | def patch(self, request): 65 | try: 66 | data = request.data 67 | order1 = order.objects.filter(id=data.get('id')) 68 | 69 | if not order1.exists(): 70 | return Response({ 71 | 'data': {}, 72 | 'message': "Order is not Found with this ID" 73 | }, status= status.HTTP_404_NOT_FOUND) 74 | 75 | serializer = OrderSerializer(order1[0], data= data, partial=True) 76 | 77 | if not serializer.is_valid(): 78 | return Response({ 79 | 'data': serializer.errors, 80 | 'message': "Something went wrong" 81 | }, status= status.HTTP_500_BAD_REQUEST) 82 | 83 | serializer.save() 84 | 85 | return Response({ 86 | 'data': serializer.data, 87 | 'message': "Order is Updated successfully" 88 | }, status= status.HTTP_200_OK) 89 | 90 | except: 91 | return Response({ 92 | 'data': {}, 93 | 'message': "Something went wrong in creation of Order" 94 | }, status= status.HTTP_400_BAD_REQUEST) 95 | 96 | def delete(self, request): 97 | try: 98 | data =request.data 99 | order1 = order.objects.filter(id =data.get('id')) 100 | 101 | if not order1.exists(): 102 | return Response({ 103 | 'data': {}, 104 | 'message': "Order is not Found with this ID" 105 | }, status= status.HTTP_404_NOT_FOUND) 106 | 107 | order1[0].delete() 108 | return Response({ 109 | 'data': {}, 110 | 'message': "Order is Deleted" 111 | }, status= status.HTTP_200_OK) 112 | 113 | except: 114 | return Response({ 115 | 'data': {}, 116 | 'message': "Something went wrong in deleting the Order" 117 | }, status= status.HTTP_400_BAD_REQUEST) 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | -------------------------------------------------------------------------------- /products/IMG_6922.JPG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codewithmuh/backend_course/c1c21c8cf0eefe9390fb7e444b7c8a0327a9e3cd/products/IMG_6922.JPG -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.6.0 2 | certifi==2022.12.7 3 | charset-normalizer==3.0.1 4 | coreapi==2.3.3 5 | coreschema==0.0.4 6 | Django==4.1.6 7 | django-rest-swagger==2.2.0 8 | djangorestframework==3.14.0 9 | drf-yasg==1.21.5 10 | idna==3.4 11 | inflection==0.5.1 12 | itypes==1.2.0 13 | Jinja2==3.1.2 14 | MarkupSafe==2.1.2 15 | openapi-codec==1.3.2 16 | packaging==23.0 17 | #psycopg2==2.9.5 18 | psycopg2-binary==2.9.5 19 | pytz==2022.7.1 20 | requests==2.28.2 21 | ruamel.yaml==0.17.21 22 | ruamel.yaml.clib==0.2.7 23 | simplejson==3.18.3 24 | sqlparse==0.4.3 25 | uritemplate==4.1.1 26 | urllib3==1.26.14 27 | -------------------------------------------------------------------------------- /vercel.json: -------------------------------------------------------------------------------- 1 | { 2 | "builds": [{ 3 | "src": "backend/wsgi.py", 4 | "use": "@vercel/python", 5 | "config": { "maxLambdaSize": "15mb", "runtime": "python3.9" } 6 | }, 7 | { 8 | "src": "build_files.sh", 9 | "use": "@vercel/static-build", 10 | "config": { "distDir": "staticfiles_build" } 11 | }], 12 | "routes": [ 13 | { 14 | "src": "/static/(.*)", 15 | "dest": "/static/$1" 16 | }, 17 | { 18 | "src": "/(.*)", 19 | "dest": "backend/wsgi.py" 20 | } 21 | ] 22 | } --------------------------------------------------------------------------------