From 8cbe5d594412929048511b3c9a68df8ff50123f1 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sat, 23 Oct 2021 20:51:03 +0200 Subject: [PATCH] Add basic API module --- api/__init__.py | 0 api/admin.py | 3 +++ api/apps.py | 6 ++++++ api/models.py | 3 +++ api/tests.py | 3 +++ api/urls.py | 6 ++++++ api/views.py | 9 +++++++++ susioma/urls.py | 1 + 8 files changed, 31 insertions(+) create mode 100644 api/__init__.py create mode 100644 api/admin.py create mode 100644 api/apps.py create mode 100644 api/models.py create mode 100644 api/tests.py create mode 100644 api/urls.py create mode 100644 api/views.py 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/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/urls.py b/api/urls.py new file mode 100644 index 0000000..2a32480 --- /dev/null +++ b/api/urls.py @@ -0,0 +1,6 @@ +from django.urls import path +from api.views import AvailabilityView + +urlpatterns = [ + path('availability/', AvailabilityView.as_view(), name="availability") +] \ No newline at end of file diff --git a/api/views.py b/api/views.py new file mode 100644 index 0000000..04deef2 --- /dev/null +++ b/api/views.py @@ -0,0 +1,9 @@ +from django.views.generic import View +from django.http import JsonResponse + +from buyer.models import Card + +class AvailabilityView(View): + def get(self, request): + cards = len(Card.objects.filter(delivered__isnull=True)) + return JsonResponse({"cards": cards}) \ No newline at end of file diff --git a/susioma/urls.py b/susioma/urls.py index 44275af..f6e7c0d 100644 --- a/susioma/urls.py +++ b/susioma/urls.py @@ -19,5 +19,6 @@ from django.urls import include, path urlpatterns = [ path('admin/', admin.site.urls), path('accounts/', include('django.contrib.auth.urls')), + path('api/', include('api.urls')), path('', include('frontend.urls')), ]