diff --git a/back/Pipfile b/back/Pipfile index 0c24bf0..b2fa8cc 100644 --- a/back/Pipfile +++ b/back/Pipfile @@ -8,6 +8,7 @@ verify_ssl = true [packages] django = "==2.1.5" django-cors-headers = "==2.4.0" +djangorestframework = "==3.8.2" gunicorn = "==19.6.0" diff --git a/back/Pipfile.lock b/back/Pipfile.lock index 5aef303..4527d5b 100644 --- a/back/Pipfile.lock +++ b/back/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "5f6bc22a581526fd5e7cba376397b8d499b15a0c071bdcc5cc799c32859f88ed" + "sha256": "b5222b4256c8f09a9b1b1d380285fa65c443f84d28dc03450684fca84b38a26b" }, "pipfile-spec": 6, "requires": { @@ -32,6 +32,14 @@ "index": "pypi", "version": "==2.4.0" }, + "djangorestframework": { + "hashes": [ + "sha256:b6714c3e4b0f8d524f193c91ecf5f5450092c2145439ac2769711f7eba89a9d9", + "sha256:c375e4f95a3a64fccac412e36fb42ba36881e52313ec021ef410b40f67cddca4" + ], + "index": "pypi", + "version": "==3.8.2" + }, "gunicorn": { "hashes": [ "sha256:723234ea1fa8dff370ab69830ba8bc37469a7cba13fd66055faeef24085e6530", diff --git a/back/__init__.py b/back/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/back/backend/__init__.py b/back/backend/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/back/backend/serializers.py b/back/backend/serializers.py index abe24ee..d5b0a6d 100644 --- a/back/backend/serializers.py +++ b/back/backend/serializers.py @@ -1,15 +1,76 @@ +# Rupika Dikkala +# January 23, 2019 +# File contains serializers needed +# to set up API end points + from rest_framework import serializers from . import models +# serializer for reports +class ReportSerializer(serializers.ModelSerializer): + # user id is foreign key...? fix this + user_id = serializers.PrimaryKeyRelatedField(many=False, read_only=True) + + class Meta: + fields = list() + model = models.Report + + if model.submitted: + fields = ( + 'user_id', + 'title', + 'date_created', + 'data_submitted', + 'submitted', + ) + else: + fields = ( + 'user_id', + 'title', + 'date_created', + 'submitted', + ) +# section serializer +class SectionSerializer(serializers.ModelSerializer): + # report id foriegn key + report_id = serializers.PrimaryKeyRelatedField(many=True, read_only=True) + -class BackendSerializer(serializers.ModelSerializer): class Meta: fields = ( - 'id', + 'report_id', + 'completed', 'title', - 'description', + 'html_description', + 'number', ) - # model = models.Backend + model = models.Section + + +class FieldSerializer(serializers.ModelSerializer): + # section_id is foriegn key + section_id = serializers.PrimaryKeyRelatedField(many=True, read_only=True) + + class Meta: + fields = ( + 'section_id', + 'label', + 'number', + 'type', + 'completed', + ) + model = models.Field + + +class DataSerializer(serializers.ModelSerializer): + field_id = serializers.PrimaryKeyRelatedField(many=False, read_only=True) + + + + + + + diff --git a/back/backend/urls.py b/back/backend/urls.py index 054413a..4697112 100644 --- a/back/backend/urls.py +++ b/back/backend/urls.py @@ -7,6 +7,9 @@ from django.urls import path from . import views urlpatterns = [ + path('', views.List.as_view()), + path('/', views.Detail.as_view()), + path('create_report/', views.create_report), path('delete_report/', views.delete_report), path('get_report/', views.get_report), diff --git a/back/backend/views.py b/back/backend/views.py index e278168..abc3083 100644 --- a/back/backend/views.py +++ b/back/backend/views.py @@ -5,7 +5,23 @@ from django.shortcuts import render from django.http import JsonResponse +from .models import * +from .serializers import * +from rest_framework import generics + + +# create sample view +class List(generics.ListCreateAPIView): + queryset = Report.objects.all() + serializer_class = ReportSerializer + +class Detail(generics.RetrieveUpdateDestroyAPIView): + queryset = Report.objects.all() + serializer_class = ReportSerializer + + +####################################### # Create Report def create_report(request): diff --git a/back/db.sqlite3 b/back/db.sqlite3 index 9f3a8ef..40ac467 100644 Binary files a/back/db.sqlite3 and b/back/db.sqlite3 differ diff --git a/back/reimbursinator/__init__.py b/back/reimbursinator/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/back/reimbursinator/urls.py b/back/reimbursinator/urls.py index 6ca7cb2..2d01ca6 100644 --- a/back/reimbursinator/urls.py +++ b/back/reimbursinator/urls.py @@ -23,5 +23,5 @@ from django.urls import path, include # add urls to this array urlpatterns = [ path('admin/', admin.site.urls), - path('backend/v1/', include("backend.urls")), + path('backend/', include("backend.urls")), ] diff --git a/back/users/__init__.py b/back/users/__init__.py deleted file mode 100644 index e69de29..0000000