Review roster API

This commit is contained in:
2022-07-12 19:00:50 +02:00
parent 2dbe01d8bd
commit cb2ff90d8a
4 changed files with 42 additions and 25 deletions

View File

@@ -12,9 +12,9 @@
{{ site_conf.footer_extended | markdown | safe }} {{ site_conf.footer_extended | markdown | safe }}
</div> </div>
</div> </div>
{% if site_conf.show_version %}
<div class="container"> <div class="container">
<p class="small text-muted">Made with ❤️ and <a href="https://github.com/daniviga/django-ram">django-ram</a> version {{ site_conf.version }}</p> <p class="small text-muted">Made with ❤️ for 🚂 and <a href="https://github.com/daniviga/django-ram">django-ram</a>
{% if site_conf.show_version %}<br/>Version {{ site_conf.version }}{% endif %}
</div> </div>
{% endif %}
</footer> </footer>

View File

@@ -29,18 +29,18 @@ urlpatterns = [
path("api/v1/dcc/", include("driver.urls")), path("api/v1/dcc/", include("driver.urls")),
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
# if settings.DEBUG: if settings.DEBUG:
# from django.views.generic import TemplateView from django.views.generic import TemplateView
# from rest_framework.schemas import get_schema_view from rest_framework.schemas import get_schema_view
#
# urlpatterns += [ urlpatterns += [
# path('swagger/', TemplateView.as_view( path('swagger/', TemplateView.as_view(
# template_name='swagger.html', template_name='swagger.html',
# extra_context={'schema_url': 'openapi-schema'} extra_context={'schema_url': 'openapi-schema'}
# ), name='swagger'), ), name='swagger'),
# path('openapi', get_schema_view( path('openapi', get_schema_view(
# title="BITE - A Basic/IoT/Example", title="RAM - Railroad Assets Manager",
# description="BITE API for IoT", description="RAM API",
# version="1.0.0" version="1.0.0"
# ), name='openapi-schema'), ), name='openapi-schema'),
# ] ]

View File

@@ -1,9 +1,9 @@
from django.urls import path from django.urls import path
from roster.views import RosterList, RosterGet, RosterAddress, RosterIdentifier from roster.views import RosterList, RosterGet, RosterAddress, RosterClass
urlpatterns = [ urlpatterns = [
path("list", RosterList.as_view()), path("list", RosterList.as_view()),
path("get/<str:uuid>", RosterGet.as_view()), path("get/<str:uuid>", RosterGet.as_view()),
path("address/<int:address>", RosterAddress.as_view()), path("address/<int:address>", RosterAddress.as_view()),
path("identifier/<str:identifier>", RosterIdentifier.as_view()), path("class/<str:class>", RosterClass.as_view()),
] ]

View File

@@ -1,4 +1,5 @@
from rest_framework.generics import ListAPIView, RetrieveAPIView from rest_framework.generics import ListAPIView, RetrieveAPIView
from rest_framework.schemas.openapi import AutoSchema
from roster.models import RollingStock from roster.models import RollingStock
from roster.serializers import RollingStockSerializer from roster.serializers import RollingStockSerializer
@@ -14,14 +15,30 @@ class RosterGet(RetrieveAPIView):
serializer_class = RollingStockSerializer serializer_class = RollingStockSerializer
lookup_field = "uuid" lookup_field = "uuid"
schema = AutoSchema(
operation_id_base="retrieveRollingStockByUUID"
)
class RosterAddress(ListAPIView): class RosterAddress(ListAPIView):
queryset = RollingStock.objects.all()
serializer_class = RollingStockSerializer serializer_class = RollingStockSerializer
lookup_field = "address"
schema = AutoSchema(
operation_id_base="retrieveRollingStockByAddress"
)
def get_queryset(self):
address = self.kwargs["address"]
return RollingStock.objects.filter(address=address)
class RosterIdentifier(RetrieveAPIView): class RosterClass(ListAPIView):
queryset = RollingStock.objects.all()
serializer_class = RollingStockSerializer serializer_class = RollingStockSerializer
lookup_field = "identifier"
schema = AutoSchema(
operation_id_base="retrieveRollingStockByClass"
)
def get_queryset(self):
_class = self.kwargs["class"]
return RollingStock.objects.filter(rolling_class__identifier=_class)