Systemy-rozmyte-sql/backend/cars/views.py
2022-01-23 19:03:55 +01:00

35 lines
1.2 KiB
Python

from rest_framework import generics
from rest_framework.views import APIView
from rest_framework.response import Response
from django.conf import settings
from .fuzzy_logic import get_fuzzy_response
from .models import Car
from .serializers import CarSerializer
from .utils import map_query_params, set_settings_values
class CarList(generics.ListAPIView):
queryset = Car.objects.all()
serializer_class = CarSerializer
def list(self, request):
values = map_query_params(request.query_params)
response = get_fuzzy_response(values, self.get_queryset())
serializer = CarSerializer(response, many=True)
return Response(serializer.data)
class SettingsAPIView(APIView):
def post(self, request, *args, **kwargs):
set_settings_values(request.data)
return Response("Settings changed")
def get(self, request, *args, **kwargs):
return Response({
'production_year':settings.PRODUCTION_YEAR,
'mileage':settings.MILEAGE,
'engine_capacity':settings.ENGINE_CAPACITY,
'combustion':settings.COMBUSTION,
'comparator':settings.COMPARATOR,
})