Gustavo Mantovani 1 vecka sedan
förälder
incheckning
668ff9f7fa
1 ändrade filer med 22 tillägg och 5 borttagningar
  1. 22 5
      app/Services/ZipCodeCoordinatesService.php

+ 22 - 5
app/Services/ZipCodeCoordinatesService.php

@@ -16,7 +16,7 @@ class ZipCodeCoordinatesService
     public function resolve(?float $latitude, ?float $longitude, ?string $zipCode): ?array
     {
         if ($latitude !== null && $longitude !== null) {
-            Log::debug('ZipCodeCoordinates resolve using address coordinates', [
+            Log::info('ZipCodeCoordinates resolve using address coordinates', [
                 'latitude'  => $latitude,
                 'longitude' => $longitude,
                 'zip_code'  => $this->normalize($zipCode),
@@ -43,15 +43,32 @@ class ZipCodeCoordinatesService
         ?float  $targetLongitude,
         ?string $targetZipCode,
     ): ?float {
+        Log::info('ZipCodeCoordinates calculate distance requested', [
+            'origin_has_latitude'  => $originLatitude !== null,
+            'origin_has_longitude' => $originLongitude !== null,
+            'origin_zip_code'      => $this->normalize($originZipCode),
+            'target_has_latitude'  => $targetLatitude !== null,
+            'target_has_longitude' => $targetLongitude !== null,
+            'target_zip_code'      => $this->normalize($targetZipCode),
+        ]);
+
         $origin = $this->resolve($originLatitude, $originLongitude, $originZipCode);
         $target = $this->resolve($targetLatitude, $targetLongitude, $targetZipCode);
 
-        return DistanceService::calculate(
+        $distance = DistanceService::calculate(
             $origin['latitude']  ?? null,
             $origin['longitude'] ?? null,
             $target['latitude']  ?? null,
             $target['longitude'] ?? null,
         );
+
+        Log::info('ZipCodeCoordinates calculate distance result', [
+            'origin_found' => $origin !== null,
+            'target_found' => $target !== null,
+            'distance_km'  => $distance,
+        ]);
+
+        return $distance;
     }
 
     public function findByZipCode(?string $zipCode): ?array
@@ -65,7 +82,7 @@ class ZipCodeCoordinatesService
         }
 
         if (array_key_exists($zipCode, $this->resolvedZipCodes)) {
-            Log::debug('ZipCodeCoordinates memory cache hit', [
+            Log::info('ZipCodeCoordinates memory cache hit', [
                 'zip_code' => $zipCode,
                 'found'    => $this->resolvedZipCodes[$zipCode] !== null,
             ]);
@@ -74,7 +91,7 @@ class ZipCodeCoordinatesService
         }
 
         if ($this->restoreFromCache($zipCode)) {
-            Log::debug('ZipCodeCoordinates persistent cache hit', [
+            Log::info('ZipCodeCoordinates persistent cache hit', [
                 'zip_code' => $zipCode,
                 'found'    => $this->resolvedZipCodes[$zipCode] !== null,
             ]);
@@ -113,7 +130,7 @@ class ZipCodeCoordinatesService
         }
 
         if ($pending === []) {
-            Log::debug('ZipCodeCoordinates preload skipped: no pending zip codes');
+            Log::info('ZipCodeCoordinates preload skipped: no pending zip codes');
 
             return;
         }