add new api
This commit is contained in:
11
core/apps/evaluation/serializers/auto/AvgCost.py
Normal file
11
core/apps/evaluation/serializers/auto/AvgCost.py
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
|
||||||
|
class AvgCostSerializer(serializers.Serializer):
|
||||||
|
brand = serializers.CharField(max_length=100)
|
||||||
|
condition = serializers.CharField(max_length=100)
|
||||||
|
model = serializers.CharField(max_length=100)
|
||||||
|
complication = serializers.CharField(max_length=100)
|
||||||
|
manufacture_date = serializers.DateField()
|
||||||
|
distance_covered = serializers.IntegerField()
|
||||||
|
color = serializers.CharField(max_length=100)
|
||||||
18
core/apps/evaluation/views/avg_cost.py
Normal file
18
core/apps/evaluation/views/avg_cost.py
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
from rest_framework import generics
|
||||||
|
from rest_framework.response import Response
|
||||||
|
from rest_framework import permissions
|
||||||
|
|
||||||
|
from core.apps.evaluation.serializers.auto.AvgCost import AvgCostSerializer
|
||||||
|
from core.services.grpc.auto import get_auto_avg_cost
|
||||||
|
|
||||||
|
|
||||||
|
class AvgCostView(generics.GenericAPIView):
|
||||||
|
serializer_class = AvgCostSerializer
|
||||||
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
|
def post(self):
|
||||||
|
serializer = self.get_serializer(data=self.request.data)
|
||||||
|
if serializer.is_valid():
|
||||||
|
avg_cost = get_auto_avg_cost(serializer.validated_data)
|
||||||
|
return Response(avg_cost, status=200)
|
||||||
|
return Response(serializer.errors, status=400)
|
||||||
Reference in New Issue
Block a user