Skip to content

Commit

Permalink
Custom get all reports route (#68)
Browse files Browse the repository at this point in the history
* remove unused routes and views

* add custom retrieve
  • Loading branch information
mateow99 authored Nov 8, 2023
1 parent 9f6c45d commit de58f7d
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 20 deletions.
3 changes: 2 additions & 1 deletion .envrctemplate
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export POSTGRES_PASSWORD=
export POSTGRES_HOST=
export POSTGRES_PORT=
export VENDOR_API_KEY=
export VENDOR_BEARER_TOKEN=
export VENDOR_BEARER_TOKEN=
export REPORT_KEY=
6 changes: 0 additions & 6 deletions src/cdn_parser/urls.py

This file was deleted.

11 changes: 1 addition & 10 deletions src/cdn_parser/views.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,3 @@
from django.shortcuts import render
from django.http import JsonResponse
from rest_framework import generics

from eatery.util.json import FieldType, error_json, success_json, verify_json_fields
from cdn_parser.controllers.populate_models import CornellDiningNowController

class PopulateModels(generics.GenericAPIView):
def get(self, request):
CornellDiningNowController().process()
return JsonResponse(success_json("Populated all models"))

# Create your views here.
1 change: 0 additions & 1 deletion src/eatery_blue_backend/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
urlpatterns = [
path("admin/", admin.site.urls),
path("eatery/", include("eatery.urls")),
path("cdn/", include("cdn_parser.urls")),
path("report/", include("report.urls")),
path("alert/", include("alert.urls")),
path("person/", include("person.urls")),
Expand Down
2 changes: 1 addition & 1 deletion src/report/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class ReportPermission(permissions.BasePermission):

def has_permission(self, request, view):
if view.action in ['create']:
if view.action in ['create', 'custom_retrieve']:
return True
return request.user.is_staff

Expand Down
15 changes: 14 additions & 1 deletion src/report/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,21 @@
from report.models import Report
from report.serializers import ReportSerializer
from .permissions import ReportPermission
from rest_framework.decorators import action
from rest_framework.response import Response
import os

class ReportViewSet(viewsets.ModelViewSet):
queryset = Report.objects.all()
serializer_class = ReportSerializer
permission_classes = [ReportPermission]
permission_classes = [ReportPermission]

@action(url_path='custom_retrieve',detail=False, methods=['GET'])
def custom_retrieve(self, request, pk=None):
if 'key' not in request.headers:
return Response({"error": "no key"}, status=401)
if request.headers['key'] != os.environ.get('REPORT_KEY'):
return Response({"error": "invalid key"}, status=401)
report = Report.objects.all()
serializer = ReportSerializer(report, many=True)
return Response(serializer.data, status=200)

0 comments on commit de58f7d

Please sign in to comment.