1
0
mirror of https://github.com/daniviga/bite.git synced 2024-11-30 00:26:13 +01:00

Telemetry is a POST only and filter GET by device (#9)

This commit is contained in:
Daniele Viganò 2020-06-05 00:15:31 +02:00 committed by GitHub
parent 973ca2decb
commit 253411c0fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 15 deletions

View File

@ -14,10 +14,13 @@ Including another URLconf
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
""" """
from django.urls import path from django.urls import path
from telemetry.views import Telemetry from telemetry.views import TelemetryView
urlpatterns = [ urlpatterns = [
path('', path('',
Telemetry.as_view({'get': 'list', 'post': 'create'}), TelemetryView.as_view({'post': 'create'}),
name='telemetry'), name='telemetry'),
path('<str:device>/',
TelemetryView.as_view({'get': 'list'}),
name='device-telemetry'),
] ]

View File

@ -1,22 +1,18 @@
from django.http import Http404
from rest_framework.viewsets import ModelViewSet from rest_framework.viewsets import ModelViewSet
from telemetry.models import Telemetry from telemetry.models import Telemetry
from telemetry.serializers import TelemetrySerializer from telemetry.serializers import TelemetrySerializer
from rest_framework.response import Response
class Telemetry(ModelViewSet): class TelemetryView(ModelViewSet):
queryset = Telemetry.objects.all() queryset = Telemetry.objects.all()
serializer_class = TelemetrySerializer serializer_class = TelemetrySerializer
# def post(self, request): def list(self, request, device=None):
# serializer = DeviceSerializer(data=request.data) queryset = Telemetry.objects.filter(device__serial=device)
# if serializer.is_valid(): if not queryset:
# serializer.save() raise Http404
# return Response(serializer.data, status=status.HTTP_201_CREATED) serializer = TelemetrySerializer(queryset, many=True)
# return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) return Response(serializer.data)
# def get(self, request):
# devices = Device.objects.all()
# import pdb; pdb.set_trace()
# serializer = DeviceSerializer(devices)
# return Response(serializer.serial)