UPDATE
This commit is contained in:
+44
-1
@@ -12,6 +12,7 @@ from rest_framework import status
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.views import APIView
|
||||
|
||||
from config.integration_contract import build_integration_meta
|
||||
from config.openapi import build_envelope_serializer, build_response
|
||||
from .models import ParameterUpdateLog, SensorData, SensorParameter
|
||||
from .serializers import (
|
||||
@@ -248,6 +249,16 @@ class FarmDataUpsertView(APIView):
|
||||
"code": 201 if created else 200,
|
||||
"msg": "success",
|
||||
"data": SensorDataResponseSerializer(farm_data).data,
|
||||
"meta": build_integration_meta(
|
||||
flow_type="ai_owned_derived_output",
|
||||
source_type="provider",
|
||||
source_service="ai_farm_data",
|
||||
ownership="ai",
|
||||
live=True,
|
||||
cached=False,
|
||||
generated_at=farm_data.updated_at,
|
||||
notes=["AI farm_data stores a derived read-model enriched with location and weather data."],
|
||||
),
|
||||
},
|
||||
status=response_status,
|
||||
)
|
||||
@@ -282,7 +293,20 @@ class FarmDetailView(APIView):
|
||||
)
|
||||
|
||||
return Response(
|
||||
{"code": 200, "msg": "success", "data": data},
|
||||
{
|
||||
"code": 200,
|
||||
"msg": "success",
|
||||
"data": data,
|
||||
"meta": build_integration_meta(
|
||||
flow_type="ai_owned_derived_output",
|
||||
source_type="db",
|
||||
source_service="ai_farm_data",
|
||||
ownership="ai",
|
||||
live=False,
|
||||
cached=True,
|
||||
snapshot_at=getattr(data, "get", lambda *_: None)("updated_at") if isinstance(data, dict) else None,
|
||||
),
|
||||
},
|
||||
status=status.HTTP_200_OK,
|
||||
)
|
||||
|
||||
@@ -327,6 +351,16 @@ class PlantCatalogSyncView(APIView):
|
||||
"count": len(snapshots),
|
||||
"plant_ids": [snapshot.backend_plant_id for snapshot in snapshots],
|
||||
},
|
||||
"meta": build_integration_meta(
|
||||
flow_type="backend_owned_data_with_ai_enrichment",
|
||||
source_type="db",
|
||||
source_service="ai_farm_data_plant_catalog",
|
||||
ownership="backend",
|
||||
live=False,
|
||||
cached=False,
|
||||
generated_at=snapshots[-1].updated_at if snapshots else None,
|
||||
notes=["Backend is canonical for plant catalog; AI stores snapshots for derived services."],
|
||||
),
|
||||
},
|
||||
status=status.HTTP_200_OK,
|
||||
)
|
||||
@@ -426,6 +460,15 @@ class SensorParameterCreateView(APIView):
|
||||
"created_at": parameter.created_at,
|
||||
"action": action,
|
||||
},
|
||||
"meta": build_integration_meta(
|
||||
flow_type="ai_owned_derived_output",
|
||||
source_type="db",
|
||||
source_service="ai_farm_parameters",
|
||||
ownership="ai",
|
||||
live=False,
|
||||
cached=False,
|
||||
generated_at=parameter.created_at,
|
||||
),
|
||||
},
|
||||
status=status.HTTP_201_CREATED,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user