From fcd2011b4dda39bb6f066c1f3039fc0b1e13ef23 Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sat, 30 Apr 2022 20:40:02 +0100 Subject: [PATCH 1/8] added initial files to project --- .github/PULL_REQUEST_TEMPLATE.md | 21 +++++ .github/workflows/ci.yml | 30 +++++++ .gitignore | 131 +++++++++++++++++++++++++++++++ LICENSE | 21 +++++ README.md | 2 + requirements.txt | 10 +++ setup.cfg | 3 + 7 files changed, 218 insertions(+) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/ci.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 requirements.txt create mode 100644 setup.cfg diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..671d248 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,21 @@ +# Description + +Please include a summary of the change and which issue is fixed. +List any dependencies that are required for this change. + + +## Type of change + +- [ ] Bug fix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) + + +# Checklist: + +- [ ] My code follows the style guidelines of this project +- [ ] I have performed a self-review of my own code +- [ ] I have commented my code, particularly in hard-to-understand areas +- [ ] My changes generate no new warnings +- [ ] Appropriate test has been written for this branch +- [ ] My coding pattern follows the PEP8 pattern and as such has passed the Flake8 Test + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..05b0f3e --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,30 @@ +name: Django CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + max-parallel: 4 + matrix: + python-version: [3.8, 3.9] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install Dependencies + run: | + python -m pip install --upgrade pip + pip install -r requirements.txt + - name: Run Tests + run: | + python manage.py test diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3a2a0a7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,131 @@ +.DS_Store +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] +*$py.class +.idea/ +# C extensions +*.so + +# Distribution / packaging +.Python +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +pip-wheel-metadata/ +share/python-wheels/ +*.egg-info/ +.installed.cfg +*.egg +MANIFEST + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.nox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*.cover +*.py,cover +.hypothesis/ +.pytest_cache/ + +# Translations +*.mo +*.pot + +# Django stuff: +*.log +local_settings.py +db.sqlite3 +db.sqlite3-journal + +# Flask stuff: +instance/ +.webassets-cache + +# Scrapy stuff: +.scrapy + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ + +# Jupyter Notebook +.ipynb_checkpoints + +# IPython +profile_default/ +ipython_config.py + +# pyenv +.python-version + +# pipenv +# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. +# However, in case of collaboration, if having platform-specific dependencies or dependencies +# having no cross-platform support, pipenv may install dependencies that don't work, or not +# install all needed dependencies. +#Pipfile.lock +Pipfile + +# PEP 582; used by e.g. github.com/David-OConnor/pyflow +__pypackages__/ + +# Celery stuff +celerybeat-schedule +celerybeat.pid + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# Spyder project settings +.spyderproject +.spyproject + +# Rope project settings +.ropeproject + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ +.dmypy.json +dmypy.json + +# Pyre type checker +.pyre/ diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..44ab27a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Michael Jamie + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..a3b38bf --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# django-zapit +A Reddit API built from a tutorial diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..b7cb331 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +asgiref==3.5.0 +Django==4.0.4 +django-shortcuts==1.6 +djangorestframework==3.13.1 +flake8==4.0.1 +mccabe==0.6.1 +pycodestyle==2.8.0 +pyflakes==2.4.0 +pytz==2022.1 +sqlparse==0.4.2 diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..5598643 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,3 @@ +[flake8] +exclude = .git,*migrations*,env +max-line-length = 130 \ No newline at end of file From e49803195490363bd6e134263d9162259ba27dc7 Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sat, 30 Apr 2022 20:58:16 +0100 Subject: [PATCH 2/8] created api app --- api/__init__.py | 0 api/admin.py | 3 +++ api/apps.py | 6 ++++++ api/migrations/__init__.py | 0 api/models.py | 3 +++ api/tests.py | 3 +++ api/views.py | 3 +++ db.sqlite3 | Bin 143360 -> 0 bytes 8 files changed, 18 insertions(+) create mode 100644 api/__init__.py create mode 100644 api/admin.py create mode 100644 api/apps.py create mode 100644 api/migrations/__init__.py create mode 100644 api/models.py create mode 100644 api/tests.py create mode 100644 api/views.py delete mode 100644 db.sqlite3 diff --git a/api/__init__.py b/api/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/admin.py b/api/admin.py new file mode 100644 index 0000000..8c38f3f --- /dev/null +++ b/api/admin.py @@ -0,0 +1,3 @@ +from django.contrib import admin + +# Register your models here. diff --git a/api/apps.py b/api/apps.py new file mode 100644 index 0000000..66656fd --- /dev/null +++ b/api/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class ApiConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'api' diff --git a/api/migrations/__init__.py b/api/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/api/models.py b/api/models.py new file mode 100644 index 0000000..71a8362 --- /dev/null +++ b/api/models.py @@ -0,0 +1,3 @@ +from django.db import models + +# Create your models here. diff --git a/api/tests.py b/api/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/api/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..91ea44a --- /dev/null +++ b/api/views.py @@ -0,0 +1,3 @@ +from django.shortcuts import render + +# Create your views here. diff --git a/db.sqlite3 b/db.sqlite3 deleted file mode 100644 index 5d5d5cc351a422d231c7e61a332f5a4f3484dcc0..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 143360 zcmeI5du$uYeaE@tV?|5k%9eG!hkagA)}2|MsC|-LUM>kO(K2m`I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i5GeFrHWWgRytFpuq-RG z%qMz!9izU4*DKmTW?|SjUcN6y;vyH0Dtwf;Jn{Ikdmg>(Kl;2AxrpNO*uMagVt3S1 zjaAXB9?ONsXCdr5&{qzmI2R3b=t}{-Y)>J6Wj-u&5%lei3Cd7NIc}(hO}4hKvH9{^ Pt3vbh08vF01lRuqp2%Ii From 19822816b5527b27e38b6e9e765a30693bc2a66e Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sat, 30 Apr 2022 21:04:16 +0100 Subject: [PATCH 3/8] added api to settings and urls --- api/urls.py | 0 todowoo/settings.py | 7 +++++++ todowoo/urls.py | 5 ++++- 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 api/urls.py diff --git a/api/urls.py b/api/urls.py new file mode 100644 index 0000000..e69de29 diff --git a/todowoo/settings.py b/todowoo/settings.py index 2b8d6de..6c5170d 100644 --- a/todowoo/settings.py +++ b/todowoo/settings.py @@ -37,7 +37,14 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + + # APPS 'todo', + 'api', + + + # PIP INSTALLS + 'rest_framework', ] MIDDLEWARE = [ diff --git a/todowoo/urls.py b/todowoo/urls.py index 0c23a6b..12ae2d6 100644 --- a/todowoo/urls.py +++ b/todowoo/urls.py @@ -14,7 +14,7 @@ 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path +from django.urls import path, include from todo import views urlpatterns = [ @@ -33,4 +33,7 @@ path('todo/', views.viewtodo, name='viewtodo'), path('todo//complete', views.completetodo, name='completetodo'), path('todo//delete', views.deletetodo, name='deletetodo'), + + # Api + path('api/v1/', include('api.urls')) ] From 3f5d7f51afec03128f3922f14d656af81801499c Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sat, 30 Apr 2022 21:36:13 +0100 Subject: [PATCH 4/8] added serializers and created todoCompletedView --- api/serializers.py | 11 +++++++++++ api/urls.py | 7 +++++++ api/views.py | 12 ++++++++++-- todowoo/urls.py | 2 +- 4 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 api/serializers.py diff --git a/api/serializers.py b/api/serializers.py new file mode 100644 index 0000000..d8aaa90 --- /dev/null +++ b/api/serializers.py @@ -0,0 +1,11 @@ +from rest_framework import serializers + +from todo.models import Todo + +class TodoSerializer(serializers.ModelSerializer): + created = serializers.ReadOnlyField() + datecompleted = serializers.ReadOnlyField() + + class Meta: + model = Todo + exclude = ['user'] \ No newline at end of file diff --git a/api/urls.py b/api/urls.py index e69de29..93d006f 100644 --- a/api/urls.py +++ b/api/urls.py @@ -0,0 +1,7 @@ +from django.urls import path + +from . import views + +urlpatterns = [ + path('completed/', views.TodoCompletedList.as_view(), name='todo-completed'), +] diff --git a/api/views.py b/api/views.py index 91ea44a..0ef9451 100644 --- a/api/views.py +++ b/api/views.py @@ -1,3 +1,11 @@ -from django.shortcuts import render +from rest_framework import generics, permissions -# Create your views here. +from . import serializers +from todo.models import Todo + + +class TodoCompletedList(generics.ListAPIView): + serializer_class = serializers.TodoSerializer + queryset = Todo.objects.all() + permission_class = [permissions.IsAuthenticated] + diff --git a/todowoo/urls.py b/todowoo/urls.py index 12ae2d6..46e406f 100644 --- a/todowoo/urls.py +++ b/todowoo/urls.py @@ -35,5 +35,5 @@ path('todo//delete', views.deletetodo, name='deletetodo'), # Api - path('api/v1/', include('api.urls')) + path('api/v1/', include('api.urls')), ] From b2dd9560c62d38a1fdd9565a671a1b43cbe58f57 Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sat, 30 Apr 2022 23:53:56 +0100 Subject: [PATCH 5/8] created todo list and create view --- api/urls.py | 1 + api/views.py | 24 +++++++++++++++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/api/urls.py b/api/urls.py index 93d006f..e8065d7 100644 --- a/api/urls.py +++ b/api/urls.py @@ -3,5 +3,6 @@ from . import views urlpatterns = [ + path('todos/', views.TodoCreate.as_view(), name='todo-create'), path('completed/', views.TodoCompletedList.as_view(), name='todo-completed'), ] diff --git a/api/views.py b/api/views.py index 0ef9451..f240ecb 100644 --- a/api/views.py +++ b/api/views.py @@ -1,4 +1,4 @@ -from rest_framework import generics, permissions +from rest_framework import generics, permissions, response, status from . import serializers from todo.models import Todo @@ -6,6 +6,24 @@ class TodoCompletedList(generics.ListAPIView): serializer_class = serializers.TodoSerializer - queryset = Todo.objects.all() - permission_class = [permissions.IsAuthenticated] + permission_classes = [permissions.IsAuthenticated] + + def get_queryset(self): + user = self.request.user + todos = Todo.objects.filter(user=user, datecompleted__isnull=False).order_by('-datecompleted') + return todos + + +class TodoCreate(generics.ListCreateAPIView): + serializer_class = serializers.TodoSerializer + permission_classes = [permissions.IsAuthenticated] + + def get_queryset(self): + user = self.request.user + todos = Todo.objects.filter(user=user, datecompleted__isnull=True) + return todos + + def perform_create(self, serializer): + serializer.save(user=self.request.user) + From fde8e6f3c0edc767a11eff1e5b7f4a51d43341b9 Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sat, 30 Apr 2022 23:58:11 +0100 Subject: [PATCH 6/8] created update and destroy view for todos --- api/urls.py | 1 + api/views.py | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/api/urls.py b/api/urls.py index e8065d7..8a9c9df 100644 --- a/api/urls.py +++ b/api/urls.py @@ -4,5 +4,6 @@ urlpatterns = [ path('todos/', views.TodoCreate.as_view(), name='todo-create'), + path('todos/', views.TodoUpdate.as_view(), name='todo-create'), path('completed/', views.TodoCompletedList.as_view(), name='todo-completed'), ] diff --git a/api/views.py b/api/views.py index f240ecb..dc9284a 100644 --- a/api/views.py +++ b/api/views.py @@ -25,5 +25,13 @@ def get_queryset(self): def perform_create(self, serializer): serializer.save(user=self.request.user) + +class TodoUpdate(generics.RetrieveUpdateDestroyAPIView): + serializer_class = serializers.TodoSerializer + permission_classes = [permissions.IsAuthenticated] + + def get_queryset(self): + return Todo.objects.filter(user=self.request.user) + From 7255d3e67fa5b0ea8a242cb2b19f9c6077270cd6 Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sun, 1 May 2022 00:34:22 +0100 Subject: [PATCH 7/8] completed todo --- api/serializers.py | 9 ++++++++- api/urls.py | 1 + api/views.py | 14 +++++++++++++- 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/api/serializers.py b/api/serializers.py index d8aaa90..1cf8926 100644 --- a/api/serializers.py +++ b/api/serializers.py @@ -8,4 +8,11 @@ class TodoSerializer(serializers.ModelSerializer): class Meta: model = Todo - exclude = ['user'] \ No newline at end of file + exclude = ['user'] + + +class TodoCompleteSerializer(serializers.ModelSerializer): + class Meta: + model = Todo + fields = ['id'] + read_only_fields = ['__all__'] diff --git a/api/urls.py b/api/urls.py index 8a9c9df..e1c49cf 100644 --- a/api/urls.py +++ b/api/urls.py @@ -5,5 +5,6 @@ urlpatterns = [ path('todos/', views.TodoCreate.as_view(), name='todo-create'), path('todos/', views.TodoUpdate.as_view(), name='todo-create'), + path('todos//ok', views.TodoOk.as_view(), name='todo-ok'), path('completed/', views.TodoCompletedList.as_view(), name='todo-completed'), ] diff --git a/api/views.py b/api/views.py index dc9284a..e5a3dcf 100644 --- a/api/views.py +++ b/api/views.py @@ -1,4 +1,5 @@ -from rest_framework import generics, permissions, response, status +from django.utils import timezone +from rest_framework import generics, permissions, response from . import serializers from todo.models import Todo @@ -33,5 +34,16 @@ class TodoUpdate(generics.RetrieveUpdateDestroyAPIView): def get_queryset(self): return Todo.objects.filter(user=self.request.user) + +class TodoOk(generics.UpdateAPIView): + serializer_class = serializers.TodoCompleteSerializer + permission_classes = [permissions.IsAuthenticated] + + def get_queryset(self): + return Todo.objects.filter(user=self.request.user) + + def perform_update(self, serializer): + serializer.instance.datecompleted = timezone.now() + serializer.save() From 1d5f720f881d7332c150ff8e961f5f8f7316a4ec Mon Sep 17 00:00:00 2001 From: kramstyles Date: Sun, 1 May 2022 00:51:03 +0100 Subject: [PATCH 8/8] added swagger docs --- api/urls.py | 22 ++++++++++++++++++++++ requirements.txt | 17 +++++++++++++++++ todowoo/settings.py | 1 + 3 files changed, 40 insertions(+) diff --git a/api/urls.py b/api/urls.py index e1c49cf..6908b21 100644 --- a/api/urls.py +++ b/api/urls.py @@ -1,10 +1,32 @@ from django.urls import path +from rest_framework import permissions +from drf_yasg.views import get_schema_view +from drf_yasg import openapi from . import views +schema_view = get_schema_view( + openapi.Info( + title="ToDo Woo API", + default_version='v1', + description="Connecting API to a todo app", + terms_of_service="https://www.google.com/policies/terms/", + contact=openapi.Contact(email="kramstyles@outlook.com"), + license=openapi.License(name="MIT License"), + ), + public=True, + permission_classes=(permissions.AllowAny,), +) + + urlpatterns = [ path('todos/', views.TodoCreate.as_view(), name='todo-create'), path('todos/', views.TodoUpdate.as_view(), name='todo-create'), path('todos//ok', views.TodoOk.as_view(), name='todo-ok'), path('completed/', views.TodoCompletedList.as_view(), name='todo-completed'), + + # API DOCUMENTATION + path('json/', schema_view.without_ui(cache_timeout=0), name='schema-json'), + path('', schema_view.with_ui('swagger', cache_timeout=0), name='schema-swagger-ui'), + path('redoc/', schema_view.with_ui('redoc', cache_timeout=0), name='schema-redoc'), ] diff --git a/requirements.txt b/requirements.txt index b7cb331..9b4786e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,10 +1,27 @@ asgiref==3.5.0 +certifi==2021.10.8 +charset-normalizer==2.0.12 +coreapi==2.3.3 +coreschema==0.0.4 Django==4.0.4 django-shortcuts==1.6 djangorestframework==3.13.1 +drf-yasg==1.20.0 flake8==4.0.1 +idna==3.3 +inflection==0.5.1 +itypes==1.2.0 +Jinja2==3.1.2 +MarkupSafe==2.1.1 mccabe==0.6.1 +packaging==21.3 pycodestyle==2.8.0 pyflakes==2.4.0 +pyparsing==3.0.8 pytz==2022.1 +requests==2.27.1 +ruamel.yaml==0.17.21 +ruamel.yaml.clib==0.2.6 sqlparse==0.4.2 +uritemplate==4.1.1 +urllib3==1.26.9 diff --git a/todowoo/settings.py b/todowoo/settings.py index 6c5170d..dbd4552 100644 --- a/todowoo/settings.py +++ b/todowoo/settings.py @@ -45,6 +45,7 @@ # PIP INSTALLS 'rest_framework', + 'drf_yasg', ] MIDDLEWARE = [