This commit is contained in:
2026-04-07 01:08:41 +03:30
parent ff464cb4a5
commit 5acee1fa2c
5 changed files with 198 additions and 34 deletions
+15 -2
View File
@@ -21,9 +21,10 @@ from .serializers import (
SensorParameterSerializer,
)
from .services import (
ExternalDataSyncError,
ensure_location_and_weather_data,
get_farm_details,
resolve_center_location_from_boundary,
resolve_weather_for_location,
)
@@ -93,6 +94,10 @@ class FarmDataUpsertView(APIView):
SensorDataValidationErrorSerializer,
"داده ورودی نامعتبر است.",
),
502: build_response(
SensorDataNotFoundSerializer,
"واکشی داده خاک یا آب‌وهوا از سرویس بیرونی ناموفق بود.",
),
},
examples=[
OpenApiExample(
@@ -171,7 +176,15 @@ class FarmDataUpsertView(APIView):
{"code": 400, "msg": "داده نامعتبر.", "data": {"farm_boundary": [str(exc)]}},
status=status.HTTP_400_BAD_REQUEST,
)
weather_forecast = resolve_weather_for_location(center_location)
try:
center_location, weather_forecast = ensure_location_and_weather_data(
center_location
)
except ExternalDataSyncError as exc:
return Response(
{"code": 502, "msg": str(exc), "data": None},
status=status.HTTP_502_BAD_GATEWAY,
)
with transaction.atomic():
farm_data, created = SensorData.objects.get_or_create(