Systemy-rozmyte-sql/backend/cars/views.py

26 lines
821 B
Python
Raw Normal View History

2022-01-23 13:45:56 +01:00
import re
2022-01-15 17:40:16 +01:00
from rest_framework import generics
2022-01-23 13:45:56 +01:00
from rest_framework.views import APIView
2022-01-03 00:09:16 +01:00
from rest_framework.response import Response
2022-01-16 16:06:58 +01:00
from .fuzzy_logic import get_fuzzy_response
2022-01-15 17:40:16 +01:00
from .models import Car
from .serializers import CarSerializer
2022-01-23 13:45:56 +01:00
from .utils import map_query_params, set_settings_values
2022-01-15 17:40:16 +01:00
class CarList(generics.ListAPIView):
queryset = Car.objects.all()
serializer_class = CarSerializer
2022-01-23 13:45:56 +01:00
2022-01-15 17:40:16 +01:00
def list(self, request):
values = map_query_params(request.query_params)
2022-01-23 12:15:33 +01:00
response = get_fuzzy_response(values, self.get_queryset())
serializer = CarSerializer(response, many=True)
2022-01-23 13:45:56 +01:00
return Response(serializer.data)
class SettingsAPIView(APIView):
def post(self, request, *args, **kwargs):
set_settings_values(request.data)
return Response("Settings changed")