2026-02-25 12:21:53 +03:30
|
|
|
"""
|
|
|
|
|
Fertilization Recommendation API views.
|
|
|
|
|
"""
|
|
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
from rest_framework import serializers, status
|
|
|
|
|
from rest_framework.response import Response
|
|
|
|
|
from rest_framework.views import APIView
|
|
|
|
|
from drf_spectacular.types import OpenApiTypes
|
2026-03-26 15:39:31 +03:30
|
|
|
from drf_spectacular.utils import OpenApiParameter, extend_schema
|
2026-02-25 12:21:53 +03:30
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
from config.swagger import status_response
|
2026-03-25 00:51:04 +03:30
|
|
|
from external_api_adapter import request as external_api_request
|
|
|
|
|
from .mock_data import CONFIG_RESPONSE_DATA
|
2026-03-26 15:39:31 +03:30
|
|
|
from .serializers import (
|
|
|
|
|
FertilizationRecommendRequestSerializer,
|
|
|
|
|
FertilizationRecommendResponseDataSerializer,
|
|
|
|
|
FertilizationTaskStatusDataSerializer,
|
|
|
|
|
FertilizationTaskSubmitDataSerializer,
|
|
|
|
|
)
|
2026-02-25 12:21:53 +03:30
|
|
|
|
|
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
class ConfigView(APIView):
|
|
|
|
|
@extend_schema(
|
|
|
|
|
tags=["Fertilization Recommendation"],
|
|
|
|
|
responses={200: status_response("FertilizationConfigResponse", data=serializers.JSONField())},
|
|
|
|
|
)
|
2026-02-25 12:21:53 +03:30
|
|
|
def get(self, request):
|
2026-03-26 15:39:31 +03:30
|
|
|
return Response({"status": "success", "data": CONFIG_RESPONSE_DATA}, status=status.HTTP_200_OK)
|
2026-02-25 12:21:53 +03:30
|
|
|
|
|
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
class RecommendView(APIView):
|
|
|
|
|
@extend_schema(
|
|
|
|
|
tags=["Fertilization Recommendation"],
|
2026-03-26 15:39:31 +03:30
|
|
|
request=FertilizationRecommendRequestSerializer,
|
|
|
|
|
responses={200: status_response("FertilizationRecommendResponse", data=FertilizationRecommendResponseDataSerializer())},
|
2026-03-24 20:10:48 +03:30
|
|
|
)
|
2026-02-25 12:21:53 +03:30
|
|
|
def post(self, request):
|
2026-03-25 00:51:04 +03:30
|
|
|
adapter_response = external_api_request(
|
|
|
|
|
"ai",
|
|
|
|
|
"/fertilization/recommend",
|
|
|
|
|
method="POST",
|
|
|
|
|
payload=request.data,
|
2026-02-25 12:21:53 +03:30
|
|
|
)
|
2026-03-25 00:51:04 +03:30
|
|
|
return Response(adapter_response.data, status=adapter_response.status_code)
|
2026-03-26 15:39:31 +03:30
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RecommendTaskStatusView(APIView):
|
|
|
|
|
@extend_schema(
|
|
|
|
|
tags=["Fertilization Recommendation"],
|
|
|
|
|
parameters=[
|
|
|
|
|
OpenApiParameter(name="task_id", type=OpenApiTypes.STR, location=OpenApiParameter.PATH),
|
|
|
|
|
],
|
|
|
|
|
responses={200: status_response("FertilizationRecommendTaskStatusResponse", data=FertilizationTaskStatusDataSerializer())},
|
|
|
|
|
)
|
|
|
|
|
def get(self, request, task_id):
|
|
|
|
|
adapter_response = external_api_request(
|
|
|
|
|
"ai",
|
|
|
|
|
f"/fertilization/status/{task_id}",
|
|
|
|
|
method="GET",
|
|
|
|
|
)
|
|
|
|
|
return Response(adapter_response.data, status=adapter_response.status_code)
|