Small refactoring
This commit is contained in:
@@ -3,10 +3,12 @@ from django.urls import path
|
|||||||
import api.countries.views
|
import api.countries.views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", api.countries.views.CountryListView.as_view(), name="countries"),
|
path(
|
||||||
|
"", api.countries.views.CountryListApiView.as_view(), name="countries"
|
||||||
|
),
|
||||||
path(
|
path(
|
||||||
"/<str:alpha2>",
|
"/<str:alpha2>",
|
||||||
api.countries.views.CountryByAlpha2View.as_view(),
|
api.countries.views.CountryByAlpha2ApiView.as_view(),
|
||||||
name="country_by_alpha2",
|
name="country_by_alpha2",
|
||||||
),
|
),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ from api.countries.models import Country
|
|||||||
from api.countries.serializers import CountrySerializer
|
from api.countries.serializers import CountrySerializer
|
||||||
|
|
||||||
|
|
||||||
class CountryListView(ListAPIView):
|
class CountryListApiView(ListAPIView):
|
||||||
queryset = Country.objects.all().order_by("alpha2")
|
queryset = Country.objects.all().order_by("alpha2")
|
||||||
serializer_class = CountrySerializer
|
serializer_class = CountrySerializer
|
||||||
|
|
||||||
@@ -28,7 +28,7 @@ class CountryListView(ListAPIView):
|
|||||||
return queryset
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
class CountryByAlpha2View(RetrieveAPIView):
|
class CountryByAlpha2ApiView(RetrieveAPIView):
|
||||||
queryset = Country.objects.all()
|
queryset = Country.objects.all()
|
||||||
serializer_class = CountrySerializer
|
serializer_class = CountrySerializer
|
||||||
lookup_field = "alpha2"
|
lookup_field = "alpha2"
|
||||||
|
|||||||
@@ -3,5 +3,5 @@ from django.urls import path
|
|||||||
import api.ping.views
|
import api.ping.views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", api.ping.views.PingView.as_view(), name="ping"),
|
path("", api.ping.views.PingApiView.as_view(), name="ping"),
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ from rest_framework.response import Response
|
|||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
|
||||||
|
|
||||||
class PingView(APIView):
|
class PingApiView(APIView):
|
||||||
def get(self, request):
|
def get(self, request):
|
||||||
data = {"message": "ok"}
|
data = {"message": "ok"}
|
||||||
return Response(data, status=status.HTTP_200_OK)
|
return Response(data, status=status.HTTP_200_OK)
|
||||||
|
|||||||
Reference in New Issue
Block a user