UPDATE
This commit is contained in:
+15
-2
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user