From f1b08e1c973ae12691794aee03014a4d38b962b6 Mon Sep 17 00:00:00 2001 From: alhanoof alsagir <106310608+alhanoofalsagir@users.noreply.github.com> Date: Mon, 1 Aug 2022 02:20:17 +0300 Subject: [PATCH] Add files via upload --- ecommerce/db.sqlite3 | 0 ecommerce/ecommerce/__init__.py | 0 .../__pycache__/__init__.cpython-39.pyc | Bin 0 -> 157 bytes .../__pycache__/settings.cpython-39.pyc | Bin 0 -> 2333 bytes .../ecommerce/__pycache__/urls.cpython-39.pyc | Bin 0 -> 992 bytes .../ecommerce/__pycache__/wsgi.cpython-39.pyc | Bin 0 -> 564 bytes ecommerce/ecommerce/asgi.py | 16 ++ ecommerce/ecommerce/settings.py | 125 ++++++++++ ecommerce/ecommerce/urls.py | 22 ++ ecommerce/ecommerce/wsgi.py | 16 ++ ecommerce/manage.py | 22 ++ ecommerce/product/__init__.py | 0 .../__pycache__/__init__.cpython-39.pyc | Bin 0 -> 155 bytes .../product/__pycache__/admin.cpython-39.pyc | Bin 0 -> 196 bytes .../product/__pycache__/apps.cpython-39.pyc | Bin 0 -> 434 bytes .../product/__pycache__/models.cpython-39.pyc | Bin 0 -> 928 bytes .../__pycache__/serializers.cpython-39.pyc | Bin 0 -> 940 bytes .../product/__pycache__/urls.cpython-39.pyc | Bin 0 -> 784 bytes .../product/__pycache__/views.cpython-39.pyc | Bin 0 -> 4466 bytes ecommerce/product/admin.py | 3 + ecommerce/product/apps.py | 6 + ecommerce/product/migrations/__init__.py | 0 .../__pycache__/__init__.cpython-39.pyc | Bin 0 -> 166 bytes ecommerce/product/models.py | 21 ++ ecommerce/product/serializers.py | 15 ++ ecommerce/product/tests.py | 3 + ecommerce/product/urls.py | 18 ++ ecommerce/product/views.py | 229 ++++++++++++++++++ 28 files changed, 496 insertions(+) create mode 100644 ecommerce/db.sqlite3 create mode 100644 ecommerce/ecommerce/__init__.py create mode 100644 ecommerce/ecommerce/__pycache__/__init__.cpython-39.pyc create mode 100644 ecommerce/ecommerce/__pycache__/settings.cpython-39.pyc create mode 100644 ecommerce/ecommerce/__pycache__/urls.cpython-39.pyc create mode 100644 ecommerce/ecommerce/__pycache__/wsgi.cpython-39.pyc create mode 100644 ecommerce/ecommerce/asgi.py create mode 100644 ecommerce/ecommerce/settings.py create mode 100644 ecommerce/ecommerce/urls.py create mode 100644 ecommerce/ecommerce/wsgi.py create mode 100644 ecommerce/manage.py create mode 100644 ecommerce/product/__init__.py create mode 100644 ecommerce/product/__pycache__/__init__.cpython-39.pyc create mode 100644 ecommerce/product/__pycache__/admin.cpython-39.pyc create mode 100644 ecommerce/product/__pycache__/apps.cpython-39.pyc create mode 100644 ecommerce/product/__pycache__/models.cpython-39.pyc create mode 100644 ecommerce/product/__pycache__/serializers.cpython-39.pyc create mode 100644 ecommerce/product/__pycache__/urls.cpython-39.pyc create mode 100644 ecommerce/product/__pycache__/views.cpython-39.pyc create mode 100644 ecommerce/product/admin.py create mode 100644 ecommerce/product/apps.py create mode 100644 ecommerce/product/migrations/__init__.py create mode 100644 ecommerce/product/migrations/__pycache__/__init__.cpython-39.pyc create mode 100644 ecommerce/product/models.py create mode 100644 ecommerce/product/serializers.py create mode 100644 ecommerce/product/tests.py create mode 100644 ecommerce/product/urls.py create mode 100644 ecommerce/product/views.py diff --git a/ecommerce/db.sqlite3 b/ecommerce/db.sqlite3 new file mode 100644 index 00000000..e69de29b diff --git a/ecommerce/ecommerce/__init__.py b/ecommerce/ecommerce/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ecommerce/ecommerce/__pycache__/__init__.cpython-39.pyc b/ecommerce/ecommerce/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..8cb3f73108d0c22a71da192669f96b6d3b06a178 GIT binary patch literal 157 zcmYe~<>g`kfxpj^K-6OpfeaXd90wpSW&si@48aVVjD9N_ia^2$;+K=NRZM7cYEf}a zVopY4UW`j>adt_5L5xdQVqSWFyia11Nla>Ter|4RQF1C0D?UCmFS8^*Uaz3?7Kcr4 QeoARhsvXGe&p^xo0G6jGHUIzs literal 0 HcmV?d00001 diff --git a/ecommerce/ecommerce/__pycache__/settings.cpython-39.pyc b/ecommerce/ecommerce/__pycache__/settings.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..651829fd1c565235d57c38c34567fc09d040a5af GIT binary patch literal 2333 zcmb7F+iu%N5G7^m62)>H+qpDB3l_a3vTG_qoWux>?(WQ-8J?ZlwMwNT2iLDBzjw6~ z$NiQJCa)X}UcpO$h6Zs4hj^56csFBYcn)Xq%n$sJ!cW|Oc0X(6(2S8sf>E$J<8W`!Z!!s>nLx`B9I^fC9>iNp77}Ud%@<75}GyUPzlZ99J+CzL-X%5gg0)Wn`i-a zZlcAsT}sqC3U{cw2;b3Eeerp^uE)=$^)v?^_bjaYbd{@@!wEm@(qn zRP6hKh4;-H7cVc_rM9+Qg2E$rdIVi<|tWAOn>tyV4M5>KSe3fNflff!Q25y!A= z(j(~^SZ@NV>jzjQ9yo94>{S4; z!u%oW(aLGal@UA}V6h)Mj_44|M8ALjOO}Vg5hj6nXgMLK|HoH=`xB1-faT@Nd@Qsr zHi$OHED(?4UKrrj)$iHz%IAll_PZDli1Wxrj{W81DEw^wi(u`^+HKMr-2s!x3 z3b2%NLfEmSCFDS-aVCq_rX7z%l_u=9(cFYp`J$5~QGHLUrl0>%r9oe+Li2{;qY2gL zQ?Xb;^kf_|jDcg)OOtlOaQY`sX`M7~jHsTldUnZAIHY&5Z}kqKaHMZH6Ixrtq(bO~ z-P~DGN@3v8s4~W3*d01hmr@r1u!m0TMpDue)yHCLETqZuj+wBqJqXJWXjzCJPQzT( zk`V5OcC>s2%>ciJ`eM<_ST_MnQ##@F66A#I=*g7w8IPA3oXW~VoZpbEuhphv2uf{7 ziwknQZKl0^tF6~sO)a{2PT3K)Ns`IHbh?aj9^t+fI_#_lQ1_fc`qm)~KZ%MkIqsJ; zaZYV+)tYK7H06dG6ksQawx>c*b7yE#3T1&z*lh?(-ANsa1DPdUgbZuMC61Mp#G8?Z zA4D&&iqs$;aYMI`J(~^A?Z3II{isyh;~38YUR@QS8N$&(dKVG0*jo*$G1JkjQ6A0& zD49z1@fa4EbbW*!Ds2!OO3L3P*g?(moj7lru-%(xoFBrb>X2@b0czudX(k&{G7r0r z?;PSdH-vq~V@6>^*3@LJ%ZbKu?&d$u|g&83uWDC~|MM22$ kaAyi9nZJb-VP425>cF9|0ZVdDK$SOlx&&I#Fn0r@2(r2qf` literal 0 HcmV?d00001 diff --git a/ecommerce/ecommerce/__pycache__/urls.cpython-39.pyc b/ecommerce/ecommerce/__pycache__/urls.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..fe21d9305210e93a7c02fa4f0501620e719cc788 GIT binary patch literal 992 zcma)5(QeZ)6m`;c?XnK|1iy8WMgnM06%5eE#H5J_U@ujr%#Cl`l-Q1J7ua6+HT+Uu zc|iOE4~T0oMG+FxEG4?Wx<2=u<7>9R9}`@=gCFykJwm>_O?UNi^9n!Xew<7R4|rGw zBAkYSi+fd1MAJz0r~QCH#3KmTJL|!1h;bkKeCIZ}4VU3`$Oj)tGGsa=1PUbt=mO~F z`wM!a|E#U|l2JfMAs$7s ztAp|Qu+_Cv0uHHU0$z+=JWk@1iW&2Gj>32c^?xjsU4eE)Qg76j&RfLt?C;6O)u+tl z4&)&Dhtat#stqsY5>4>^oU{TjbL-E!H-;h=ydGBz2MJxYR!;8hy1S0l8NMai)*gCO z?#*^ysbz)+Zaa-#!sCvUB>suROOl}JGcHP*giYieZw77k&5qA!H$xl@zA0>WGioCb z@h;hI26>JHl;_h2EoYQ!bvbtfO`5%q5RLDM=*XobQ(9;uC$HJ-T=_Sm-Lvz*U&kkt z*`)z(W~^EPI!dVDqEd-zU?F9BNu$H^b)wNmp}--!O6gfwL%W+pPN9T`IyEkdb8tezEXeX|yq2q#7D;iMT>BZl zw8wr@bqxga3xPtlYZ@%j(~O3h_huxvzaOJ|{e77Ih!DDOoDFCP`$O3FAOJ@b#3PPn zG>O95lDKS5S`mV1+5Wl3+kER64qod!nrw4CM!oI3Kk=9GU`TSU=As~TZ3yJLEWzYJ zDx;T>yCjZ>j=;A{Td>3}fUHxPlx!w}FiRLIHNTedPQnT#SurD;kYXipGM%!jk|JkL zXf>UNdY=MMsSOaJ0%h3*h*qJvuw*VIyd@SOUN~3Tqcr6@w+UY|Rp|ekg2)t9dYBxf z3w`5s%Au0_wglzU8(WApehdRaqh91+7vN}pM>k~nH~r5iqrn9opI%-LM}sjvzvy3` zo!-5A?mw~MoKS`Bb$o}?Ac9hlwe>I8Qj$D$kko|@4phDaY9)+TJ`RZ-=ImNJzq`Tt z8=3ks8+bbYc$8gPFg9ay!Bo}<`_<_x>o;xEGd4TSo~3M9HD6NQ`tJMn$dALXK(-s8 Lz0<{e_yzt4J1w!` literal 0 HcmV?d00001 diff --git a/ecommerce/ecommerce/asgi.py b/ecommerce/ecommerce/asgi.py new file mode 100644 index 00000000..d3a9622b --- /dev/null +++ b/ecommerce/ecommerce/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for ecommerce 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/4.0/howto/deployment/asgi/ +""" + +import os + +from django.core.asgi import get_asgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerce.settings') + +application = get_asgi_application() diff --git a/ecommerce/ecommerce/settings.py b/ecommerce/ecommerce/settings.py new file mode 100644 index 00000000..116658de --- /dev/null +++ b/ecommerce/ecommerce/settings.py @@ -0,0 +1,125 @@ +""" +Django settings for ecommerce project. + +Generated by 'django-admin startproject' using Django 4.0.6. + +For more information on this file, see +https://docs.djangoproject.com/en/4.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/4.0/ref/settings/ +""" + +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/4.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = 'django-insecure--^t*+$v!fbeehil0mdlg&1zu#8%r4347d+mx58g6(+v54*j)08' + +# SECURITY WARNING: don't run with debug turned on in production! +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', + 'product.apps.ProductConfig', + 'rest_framework', +] + +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 = 'ecommerce.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 = 'ecommerce.wsgi.application' + + +# Database +# https://docs.djangoproject.com/en/4.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': BASE_DIR / 'db.sqlite3', + } +} + + +# Password validation +# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators + +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', + }, +] + + +# Internationalization +# https://docs.djangoproject.com/en/4.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_TZ = True + + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/4.0/howto/static-files/ + +STATIC_URL = 'static/' + +# Default primary key field type +# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field + +DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' diff --git a/ecommerce/ecommerce/urls.py b/ecommerce/ecommerce/urls.py new file mode 100644 index 00000000..36dc6f26 --- /dev/null +++ b/ecommerce/ecommerce/urls.py @@ -0,0 +1,22 @@ +"""ecommerce URL Configuration + +The `urlpatterns` list routes URLs to views. For more information please see: + https://docs.djangoproject.com/en/4.0/topics/http/urls/ +Examples: +Function views + 1. Add an import: from my_app import views + 2. Add a URL to urlpatterns: path('', views.home, name='home') +Class-based views + 1. Add an import: from other_app.views import Home + 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') +Including another URLconf + 1. Import the include() function: from django.urls import include, path + 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) +""" +from django.contrib import admin +from django.urls import path , include + +urlpatterns = [ + path('admin/', admin.site.urls), + path('product/' , include("product.urls")), +] diff --git a/ecommerce/ecommerce/wsgi.py b/ecommerce/ecommerce/wsgi.py new file mode 100644 index 00000000..08ec9c52 --- /dev/null +++ b/ecommerce/ecommerce/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for ecommerce 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/4.0/howto/deployment/wsgi/ +""" + +import os + +from django.core.wsgi import get_wsgi_application + +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'ecommerce.settings') + +application = get_wsgi_application() diff --git a/ecommerce/manage.py b/ecommerce/manage.py new file mode 100644 index 00000000..f089920d --- /dev/null +++ b/ecommerce/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', 'ecommerce.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/ecommerce/product/__init__.py b/ecommerce/product/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ecommerce/product/__pycache__/__init__.cpython-39.pyc b/ecommerce/product/__pycache__/__init__.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..9d9136989674bcf13bd2ada68e1d0ba1fdcac00e GIT binary patch literal 155 zcmYe~<>g`k0*Qaml0fuh5P=LBfgA@QE@lA|DGb33nv8xc8Hzx{2;!H6vsFxJacWU< zOkz$(VqT0(YH@Z+enE^&R$^Xye!Nd&l1WTza(-@ZYEg1(OhHk8N@;RQOniK1US>&r Xyk0@&Ee@MppkPj_9mwR*K+FIDRIDbR literal 0 HcmV?d00001 diff --git a/ecommerce/product/__pycache__/admin.cpython-39.pyc b/ecommerce/product/__pycache__/admin.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7b0ad1d82c64121fd59f7cfe9b277e1dc9fd0063 GIT binary patch literal 196 zcmYe~<>g`k0*QamlAM6_V-N=!FabFZKwK;UBvKes7;_kM8KW2(8B&;n88n$+0!0}# z8E>&BrsQVk`Drpm@ug%X=B4NBCFkdr6lEqAfecv5P{a(Rz{D?GXRDad;?$zzn8cin z#Jm`n)Z*-t{DK%4u)cVo#3YlL)a3l!+|;7v)R=;z{FKttpq(-6 literal 0 HcmV?d00001 diff --git a/ecommerce/product/__pycache__/apps.cpython-39.pyc b/ecommerce/product/__pycache__/apps.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b32d9b32ed400c48f4827ad29f4498d4fb94ee35 GIT binary patch literal 434 zcmYjNy-ve05Vqq~g#Ijufdz>*OC}~%p_W##pb81GM3F2v=azyKn>ZO@g@@o3cqOk$ zNW20A;+#~XC*ApeK7aQkMx#DKIr{xtzT^ApgIx(Rn4sDdG(dnVQqYuAaz!8j_C|n7 z`pVJ(!dnvez7a)Y>h`C`%yhZhtaG2)6^g+G)gGdeB&9&`H%%D?X$TBiLN~gpG&FhL zQM??(gDBTJfn`!?kjf?(oAtD*_2ot?aC@dhFXEnyI4?yZId^@|5!@*64>^BogxXdP zK(0iiYA%q1uUd}K*FH$)uhE*H@$4+Sv$C?8Q1_zD=F&da+GO)~7Je<3r;3X7-JLjTruSFx3k_vG^A~25i>W~F5{6^;M;lZf8)*@V9rJ3Zi91wGwZQK_6Jm6 BZQ1|; literal 0 HcmV?d00001 diff --git a/ecommerce/product/__pycache__/models.cpython-39.pyc b/ecommerce/product/__pycache__/models.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..92b42215e19c764df31b4092ec789ee804dbc84c GIT binary patch literal 928 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 literal 0 HcmV?d00001 diff --git a/ecommerce/product/models.py b/ecommerce/product/models.py new file mode 100644 index 00000000..d28373e4 --- /dev/null +++ b/ecommerce/product/models.py @@ -0,0 +1,21 @@ +from django.db import models +from statistics import mode + +# Create your models here. + +class Brand(models.Model): + title = models.CharField(max_length=512) + description = models.TextField() + established_at = models.DateField() + city = models.CharField(max_length=512) + + +class Product(models.Model): + brand = models.ForeignKey(Brand, on_delete=models.CASCADE) + name = models.CharField(max_length=512) + description = models.TextField() + image_url = models.URLField() + price = models.FloatField() + quantity = models.IntegerField() + is_active = models.BooleanField() + \ No newline at end of file diff --git a/ecommerce/product/serializers.py b/ecommerce/product/serializers.py new file mode 100644 index 00000000..bab0fd3e --- /dev/null +++ b/ecommerce/product/serializers.py @@ -0,0 +1,15 @@ +from rest_framework import serializers + +from .models import Product, Brand + + +class ProductSerializer(serializers.ModelSerializer): + class Meta: + model = Product + fields = "__all__" + + +class BrandSerializer(serializers.ModelSerializer): + class Meta: + model = Brand + fields = "__all__" \ No newline at end of file diff --git a/ecommerce/product/tests.py b/ecommerce/product/tests.py new file mode 100644 index 00000000..de8bdc00 --- /dev/null +++ b/ecommerce/product/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/ecommerce/product/urls.py b/ecommerce/product/urls.py new file mode 100644 index 00000000..93799fc1 --- /dev/null +++ b/ecommerce/product/urls.py @@ -0,0 +1,18 @@ +from django.urls import path +from . import views + +app_name = "product_brand" + +urlpatterns = [ + path("create/", views.create_product, name="create_product"), + path("read/", views.read_products, name="read_products"), + path("update//", views.update_product, name="update_product"), + path("delete//", views.delete_product, name="delete_product"), + + path("brands/create/", views.create_brand, name="create_brand"), + path("brands/read/", views.read_brands, name="read_brands"), + path("brands/update//", views.update_brand, name="update_brand"), + path("brands/delete//", views.delete_brand, name="delete_brand"), + + path('brand_products//', views.read_brand_products, name="read_brand_products") +] \ No newline at end of file diff --git a/ecommerce/product/views.py b/ecommerce/product/views.py new file mode 100644 index 00000000..db883e85 --- /dev/null +++ b/ecommerce/product/views.py @@ -0,0 +1,229 @@ +from unittest import skip +from rest_framework.decorators import api_view +from rest_framework.request import Request +from rest_framework.response import Response +from rest_framework import status + +from .models import Product, Brand +from .serializers import ProductSerializer, BrandSerializer + +# Create your views here. +''' + +product + + +''' + +@api_view(["POST"]) +def create_product(request: Request): + product_serializer = ProductSerializer(data=request.data) + if product_serializer.is_valid(): + product_serializer.save() + else: + return Response( + { + "msg": "Product object invalid.", + "error": product_serializer.errors + }, + status=status.HTTP_403_FORBIDDEN + ) + + return Response( + { + "msg": "Product created." + }, + status=status.HTTP_201_CREATED + ) + + +@api_view(["GET"]) +def read_products(request: Request): + skip = int(request.query_params.get("skip", 0)) + get = int(request.query_params.get("get", 10)) + + all_products = Product.objects.all()[skip:get] + + return Response( + { + "msg": f'list of {len(all_products)} products, total products {Product.objects.count()}', + "products": ProductSerializer(instance=all_products, many=True).data + }, + status=status.HTTP_200_OK + ) + + +@api_view(["PUT"]) +def update_product(request: Request, product_id): + try: + product = Product.objects.get(id=product_id) + except Exception as e: + return Response( + { + "msg": f'product not found.', + }, + status=status.HTTP_404_NOT_FOUND + ) + product_serializer = ProductSerializer(instance=product, data=request.data) + if product_serializer.is_valid(): + product_serializer.save() + else: + return Response( + { + "msg": "Product object invalid.", + "error": product_serializer.errors + }, + status=status.HTTP_403_FORBIDDEN + ) + return Response( + { + "msg": f'product updated.', + }, + status=status.HTTP_200_OK + ) + + +@api_view(["DELETE"]) +def delete_product(request: Request, product_id): + try: + product = Product.objects.get(id=product_id) + product.delete() + except Exception as e: + return Response( + { + "msg": f'product not found.', + }, + status=status.HTTP_404_NOT_FOUND + ) + return Response( + { + "msg": f'{product.title} product deleted.', + }, + status=status.HTTP_200_OK + ) + + +''' + +Brand + + +''' + + +@api_view(["POST"]) +def create_brand(request: Request): + brand_serializer = BrandSerializer(data=request.data) + if brand_serializer.is_valid(): + brand_serializer.save() + else: + return Response( + { + "msg": "Brand object invalid.", + "error": brand_serializer.errors + }, + status=status.HTTP_403_FORBIDDEN + ) + + return Response( + { + "msg": "Brand created." + }, + status=status.HTTP_201_CREATED + ) + + +@api_view(["GET"]) +def read_brands(request: Request): + skip = int(request.query_params.get("skip", 0)) + get = int(request.query_params.get("get", 10)) + + if "search" in request.query_params: + search_phrase = request.query_params["search"] + all_products = Brand.objects.filter( + title__startswith=search_phrase)[skip:get] + else: + all_products = Brand.objects.all()[skip:get] + + return Response( + { + "msg": f'list of {len(all_products)} brands', + "brands": BrandSerializer(instance=all_products, many=True).data + }, + status=status.HTTP_200_OK + ) + + +@api_view(["PUT"]) +def update_brand(request: Request, brand_id): + try: + brand = Brand.objects.get(id=brand_id) + except Exception as e: + return Response( + { + "msg": f'brand not found.', + }, + status=status.HTTP_404_NOT_FOUND + ) + brand_serializer = BrandSerializer(instance=brand, data=request.data) + if brand_serializer.is_valid(): + brand_serializer.save() + else: + return Response( + { + "msg": "Brand object invalid.", + "error": brand_serializer.errors + }, + status=status.HTTP_403_FORBIDDEN + ) + return Response( + { + "msg": f'brand updated.', + }, + status=status.HTTP_200_OK + ) + + +@api_view(["DELETE"]) +def delete_brand(request: Request, brand_id): + try: + brand = Brand.objects.get(id=brand_id) + brand.delete() + except Exception as e: + return Response( + { + "msg": f'brand not found.', + }, + status=status.HTTP_404_NOT_FOUND + ) + return Response( + { + "msg": f'{brand.title} brand deleted.', + }, + status=status.HTTP_200_OK + ) + + +@api_view(["GET"]) +def read_brand_products(request: Request, brand_id): + skip = int(request.query_params.get("skip", 0)) + get = int(request.query_params.get("get", 10)) + + try: + brand = Brand.objects.get(id=brand_id) + except Exception as e: + return Response( + { + "msg": f'brand not found.', + }, + status=status.HTTP_404_NOT_FOUND + ) + + all_products = Product.objects.filter(brand=brand_id)[skip:get] + return Response( + { + "msg": f'list of {len(all_products)} products branded {brand.title}', + "products": ProductSerializer(instance=all_products, many=True).data + }, + status=status.HTTP_200_OK + ) \ No newline at end of file