2026-02-25 12:21:53 +03:30
|
|
|
"""
|
|
|
|
|
Irrigation Recommendation API views.
|
2026-03-24 20:10:48 +03:30
|
|
|
No database. All responses are static mock data.
|
2026-02-25 12:21:53 +03:30
|
|
|
Response format: {"status": "success", "data": <payload>}. HTTP 200 only.
|
|
|
|
|
No processing, validation, or use of input parameters in responses.
|
|
|
|
|
"""
|
|
|
|
|
|
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
|
|
|
|
|
from drf_spectacular.utils import 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-02-25 12:21:53 +03:30
|
|
|
|
|
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
class ConfigView(APIView):
|
2026-02-25 12:21:53 +03:30
|
|
|
"""
|
|
|
|
|
GET endpoint for irrigation config (farm info and crop options).
|
|
|
|
|
|
|
|
|
|
Purpose:
|
|
|
|
|
Returns static farm info (soilType, waterQuality, climateZone) and
|
|
|
|
|
crop options list for the irrigation recommendation form. Used when
|
|
|
|
|
loading the irrigation recommendation page.
|
|
|
|
|
|
|
|
|
|
Input parameters:
|
|
|
|
|
None. Query parameters, if sent, are not read or used.
|
|
|
|
|
|
|
|
|
|
Response structure:
|
|
|
|
|
- status: string, always "success".
|
|
|
|
|
- data: object with keys farmInfo (object), cropOptions (array of
|
|
|
|
|
{ id, labelKey, icon }).
|
|
|
|
|
|
|
|
|
|
No processing or validation is performed on inputs.
|
|
|
|
|
"""
|
|
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
@extend_schema(
|
|
|
|
|
tags=["Irrigation Recommendation"],
|
|
|
|
|
responses={200: status_response("IrrigationConfigResponse", data=serializers.JSONField())},
|
|
|
|
|
)
|
2026-02-25 12:21:53 +03:30
|
|
|
def get(self, request):
|
2026-03-24 20:10:48 +03:30
|
|
|
return Response(
|
2026-02-25 12:21:53 +03:30
|
|
|
{"status": "success", "data": CONFIG_RESPONSE_DATA},
|
2026-03-24 20:10:48 +03:30
|
|
|
status=status.HTTP_200_OK,
|
2026-02-25 12:21:53 +03:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
class RecommendView(APIView):
|
2026-02-25 12:21:53 +03:30
|
|
|
"""
|
|
|
|
|
POST endpoint for irrigation recommendation.
|
|
|
|
|
|
|
|
|
|
Purpose:
|
|
|
|
|
Returns a static irrigation plan (frequencyPerWeek, durationMinutes,
|
|
|
|
|
bestTimeOfDay, moistureLevel, warning). Body may contain crop_id
|
|
|
|
|
and farm info; not read or used in response.
|
|
|
|
|
|
|
|
|
|
Input parameters:
|
|
|
|
|
- body (optional): JSON. May contain "crop_id", "soilType", "waterQuality",
|
|
|
|
|
"climateZone". Data type: object. Location: body. Not read or validated;
|
|
|
|
|
not used in response.
|
|
|
|
|
|
|
|
|
|
Response structure:
|
|
|
|
|
- status: string, always "success".
|
|
|
|
|
- data: object with key "plan" (object with frequencyPerWeek,
|
|
|
|
|
durationMinutes, bestTimeOfDay, moistureLevel, warning).
|
|
|
|
|
|
|
|
|
|
No processing or validation is performed on inputs.
|
|
|
|
|
"""
|
|
|
|
|
|
2026-03-24 20:10:48 +03:30
|
|
|
@extend_schema(
|
|
|
|
|
tags=["Irrigation Recommendation"],
|
|
|
|
|
request=OpenApiTypes.OBJECT,
|
|
|
|
|
responses={200: status_response("IrrigationRecommendResponse", data=serializers.JSONField())},
|
|
|
|
|
)
|
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",
|
|
|
|
|
"/irrigation/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)
|