Commit 42e038e9 authored by Thomas Frion's avatar Thomas Frion

[FEAT] Url to search a service by his name

parent 124ab4a4
......@@ -64,7 +64,8 @@ REST_FRAMEWORK = {
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticated',),
'DEFAULT_AUTHENTICATION_CLASSES':(
'rest_framework_simplejwt.authentication.JWTAuthentication',
)
),
'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend']
}
SWAGGER_SETTINGS = {
......
......@@ -6,4 +6,6 @@ from external_service import views
urlpatterns = [
path('services/', views.ServiceList.as_view()),
path('services/<int:pk>', views.ServiceDetail.as_view()),
path('services/search', views.ServiceSearch.as_view()),
]
\ No newline at end of file
from rest_framework import status
from rest_framework import generics
from rest_framework.filters import SearchFilter
from rest_framework.views import APIView
from rest_framework.schemas import SchemaGenerator
from rest_framework.response import Response
from django.http import Http404
from drf_yasg import openapi
from drf_yasg.utils import swagger_auto_schema
from django_filters.rest_framework import DjangoFilterBackend
from external_service.serializers import *
from external_service.models import *
"""
=== Service API VIEW
"""
......@@ -71,3 +76,15 @@ class ServiceDetail(APIView):
service.delete() # We delete
# We return with HTTP code 204
return Response(status = 204)
"""
=== Service API VIEW, search service by name
"""
class ServiceSearch(generics.ListAPIView):
queryset = ExternalService.objects.all()
serializer_class = ExternalServiceSerializer
filter_backends = (SearchFilter,)
search_fields = ('name',)
......@@ -9,3 +9,4 @@ Django==3.0.4
djangorestframework-simplejwt==4.4.0
whitenoise==5.0.1
django-cors-headers==3.2.1
django-filter==2.2.0
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment