From 8f7f8dbaff277f2bf53d9f4cf7f7bdc3d992792f Mon Sep 17 00:00:00 2001 From: Nguyen Ngo Date: Thu, 11 Jun 2026 15:53:56 -0400 Subject: [PATCH] 06/11 Update API to support Mobile GPS --- app/api/inspections.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/app/api/inspections.py b/app/api/inspections.py index 2998190..b33a45d 100644 --- a/app/api/inspections.py +++ b/app/api/inspections.py @@ -322,6 +322,19 @@ def create_inspection(): if completed_at is None and status == 'completed': completed_at = now_eastern() + # ── GPS (mobile submission) ─────────────────────────────────────────── + # The iPad sends submit_latitude / submit_longitude when CoreLocation + # granted permission and a fix was obtained before the inspector confirmed + # submission. Both fields are nullable — absence is silently ignored. + _lat = data.get('submit_latitude') + _lng = data.get('submit_longitude') + try: + submit_latitude = float(_lat) if _lat is not None else None + submit_longitude = float(_lng) if _lng is not None else None + except (ValueError, TypeError): + submit_latitude = None + submit_longitude = None + inspection = Inspection( template_id = template_id, facility_id = facility_id, @@ -334,6 +347,8 @@ def create_inspection(): completed_at = completed_at if status == 'completed' else None, mobile_local_id = mobile_local_id, parent_inspection_id = parent_inspection_id, + submit_latitude = submit_latitude, + submit_longitude = submit_longitude, ) db.session.add(inspection)