Merge pull request 'add new api' (#109) from behruz into main
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 2m7s
All checks were successful
Deploy to Production / build-and-deploy (push) Successful in 2m7s
Reviewed-on: #109
This commit is contained in:
@@ -33,8 +33,10 @@ from .views import (
|
|||||||
ArchiveEvaluationrequestView, GetArchivedAutoEvaluationListAPIView, ArchivedAutoEvaluation,
|
ArchiveEvaluationrequestView, GetArchivedAutoEvaluationListAPIView, ArchivedAutoEvaluation,
|
||||||
GetArchivedQuickevaluationListAPIView, ChangeQuickevaluationAPIView, ArchivedReqEvaluation,
|
GetArchivedQuickevaluationListAPIView, ChangeQuickevaluationAPIView, ArchivedReqEvaluation,
|
||||||
GetArchivedReqEvaluationListAPIView,
|
GetArchivedReqEvaluationListAPIView,
|
||||||
|
AvgCostView,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
router = DefaultRouter()
|
router = DefaultRouter()
|
||||||
router.register("document-category", DocumentCategoryView, basename="DocumentCategory")
|
router.register("document-category", DocumentCategoryView, basename="DocumentCategory")
|
||||||
router.register("document", DocumentView, basename="Document")
|
router.register("document", DocumentView, basename="Document")
|
||||||
@@ -95,5 +97,9 @@ urlpatterns = [
|
|||||||
|
|
||||||
path("req-evaluvation-change-status/", GetArchivedReqEvaluationListAPIView.as_view(),
|
path("req-evaluvation-change-status/", GetArchivedReqEvaluationListAPIView.as_view(),
|
||||||
name="archived-req-evaluation"),
|
name="archived-req-evaluation"),
|
||||||
|
path(
|
||||||
|
"calculate_avg_cost/",
|
||||||
|
AvgCostView.as_view(),
|
||||||
|
name="calculate-avg-cost"
|
||||||
|
)
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -14,3 +14,4 @@ from .vehicle import * # noqa
|
|||||||
from .didox import * # noqa
|
from .didox import * # noqa
|
||||||
from .tech_passport import * # noqa
|
from .tech_passport import * # noqa
|
||||||
from .certificate import * # noqa
|
from .certificate import * # noqa
|
||||||
|
from .avg_cost import *
|
||||||
|
|||||||
@@ -10,9 +10,26 @@ class AvgCostView(generics.GenericAPIView):
|
|||||||
serializer_class = AvgCostSerializer
|
serializer_class = AvgCostSerializer
|
||||||
permission_classes = [permissions.IsAuthenticated]
|
permission_classes = [permissions.IsAuthenticated]
|
||||||
|
|
||||||
def post(self):
|
def post(self, request):
|
||||||
serializer = self.get_serializer(data=self.request.data)
|
serializer = self.get_serializer(data=request.data)
|
||||||
if serializer.is_valid():
|
if serializer.is_valid():
|
||||||
avg_cost = get_auto_avg_cost(serializer.validated_data)
|
print(serializer.validated_data)
|
||||||
|
brand = serializer.validated_data['brand']
|
||||||
|
condition = serializer.validated_data['condition']
|
||||||
|
model = serializer.validated_data['model']
|
||||||
|
complication = serializer.validated_data['complication']
|
||||||
|
manufacture_date = serializer.validated_data['manufacture_date']
|
||||||
|
distance_covered = serializer.validated_data['distance_covered']
|
||||||
|
color = serializer.validated_data['color']
|
||||||
|
|
||||||
|
avg_cost = get_auto_avg_cost(
|
||||||
|
brand=brand,
|
||||||
|
condition=condition,
|
||||||
|
model=model,
|
||||||
|
complication=complication,
|
||||||
|
manufacture_date=manufacture_date,
|
||||||
|
distance_covered=str(distance_covered),
|
||||||
|
color=color
|
||||||
|
)
|
||||||
return Response(avg_cost, status=200)
|
return Response(avg_cost, status=200)
|
||||||
return Response(serializer.errors, status=400)
|
return Response(serializer.errors, status=400)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from datetime import datetime
|
||||||
import grpc
|
import grpc
|
||||||
from google.protobuf.timestamp_pb2 import Timestamp
|
from google.protobuf.timestamp_pb2 import Timestamp
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
@@ -15,13 +16,17 @@ def get_auto_avg_cost(
|
|||||||
distance_covered,
|
distance_covered,
|
||||||
color
|
color
|
||||||
):
|
):
|
||||||
# url = f"{env.str('RPC_IP')}:{env.str('RPC_PORT')}"
|
channel = grpc.insecure_channel("94.230.232.47:50051")
|
||||||
# channel = grpc.insecure_channel(url)
|
|
||||||
channel = grpc.insecure_channel("192.168.1.120:50051")
|
|
||||||
stub = auto_pb2_grpc.AutoAvgCostServiceStub(channel)
|
stub = auto_pb2_grpc.AutoAvgCostServiceStub(channel)
|
||||||
|
|
||||||
|
|
||||||
ts = Timestamp()
|
ts = Timestamp()
|
||||||
ts.FromDatetime(manufacture_date)
|
if isinstance(manufacture_date, datetime):
|
||||||
|
dt = manufacture_date
|
||||||
|
else:
|
||||||
|
dt = datetime.combine(manufacture_date, datetime.min.time())
|
||||||
|
|
||||||
|
ts.FromDatetime(dt)
|
||||||
|
|
||||||
response = stub.AutoAvgCost(auto_pb2.AutoAvgCostRequest(
|
response = stub.AutoAvgCost(auto_pb2.AutoAvgCostRequest(
|
||||||
brand=brand,
|
brand=brand,
|
||||||
@@ -32,6 +37,7 @@ def get_auto_avg_cost(
|
|||||||
distance_covered=distance_covered,
|
distance_covered=distance_covered,
|
||||||
color=color,
|
color=color,
|
||||||
))
|
))
|
||||||
|
print("manufacture_date:", manufacture_date, type(manufacture_date))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"avg_cost": response.avg_cost,
|
"avg_cost": response.avg_cost,
|
||||||
|
|||||||
Reference in New Issue
Block a user