diff --git a/dcc/dcc/urls.py b/dcc/dcc/urls.py index e4ee9cb..955fc55 100644 --- a/dcc/dcc/urls.py +++ b/dcc/dcc/urls.py @@ -24,8 +24,8 @@ from driver import urls as driver_urls urlpatterns = [ path('ht/', include('health_check.urls')), path('admin/', admin.site.urls), - path('roster/', include(roster_urls)), - path('dcc/', include(driver_urls)), + path('api/v1/roster/', include(roster_urls)), + path('api/v1/dcc/', include(driver_urls)), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) # if settings.DEBUG: diff --git a/dcc/driver/urls.py b/dcc/driver/urls.py index ac0dec8..64a8e26 100644 --- a/dcc/driver/urls.py +++ b/dcc/driver/urls.py @@ -1,7 +1,8 @@ from django.urls import path -from driver.views import SendCommand, Function, Cab, Emergency, Infra +from driver.views import SendCommand, Function, Cab, Emergency, Infra, Test urlpatterns = [ + path('test', Test.as_view()), path('emergency', Emergency.as_view()), path('infra', Infra.as_view()), path('command', SendCommand.as_view()), diff --git a/dcc/driver/views.py b/dcc/driver/views.py index c5309ec..fa86425 100644 --- a/dcc/driver/views.py +++ b/dcc/driver/views.py @@ -12,6 +12,9 @@ from roster.models import Cab as CabModel def addresschecker(f): + """ + Check if DCC address does exist in the database + """ def addresslookup(request, address, *args): try: CabModel.objects.get(address=address) @@ -21,7 +24,22 @@ def addresschecker(f): return addresslookup +class Test(APIView): + """ + Send a test command + """ + parser_classes = [PlainTextParser] + + def get(self, request): + response = Connector().passthrough("") + return Response({"response": response.decode()}, + status=status.HTTP_202_ACCEPTED) + + class SendCommand(APIView): + """ + Command passthrough + """ parser_classes = [PlainTextParser] def put(self, request): @@ -40,6 +58,9 @@ class SendCommand(APIView): @method_decorator(addresschecker, name="put") class Function(APIView): + """ + Send "Function" commands to a valid DCC address + """ def put(self, request, address): serializer = FunctionSerializer(data=request.data) if serializer.is_valid(): @@ -53,6 +74,9 @@ class Function(APIView): @method_decorator(addresschecker, name="put") class Cab(APIView): + """ + Send "Cab" commands to a valid DCC address + """ def put(self, request, address): serializer = CabSerializer(data=request.data) if serializer.is_valid(): @@ -65,6 +89,9 @@ class Cab(APIView): class Infra(APIView): + """ + Send "Infra" commands to a valid DCC address + """ def put(self, request): serializer = InfraSerializer(data=request.data) if serializer.is_valid(): @@ -77,6 +104,9 @@ class Infra(APIView): class Emergency(APIView): + """ + Send an "Emergency" stop, no matter the HTTP method used + """ def put(self, request): Connector().emergency() return Response({"response": "emergency stop"},