Module 2 — Geographic Data: PSGC tables (regions/provinces/cities/ barangays) with native geometry(polygon|point, 4326) columns; cascading dropdown endpoints; ST_Contains-based GPS resolution; service-area CRUD with barangay attach/detach; SamplePsgcSeeder + psgc:import command. Module 3 — User Management: 5 role-specific profile tables (driver/ helper/scanner/store_partner with verification_status + rejection reason); profile auto-created on register; admin user CRUD with filters/pagination, suspend/activate, profile approve/reject; self-service /me + /me/profile with role-aware validation that blocks self-approval and resets rejected profiles to pending on resubmit. 69 feature tests passing. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Geo;
|
|
|
|
use App\Http\Controllers\Api\V1\ApiController;
|
|
use App\Http\Resources\BarangayResource;
|
|
use App\Services\Geo\GeoLocationService;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class ResolveLocationController extends ApiController
|
|
{
|
|
public function __invoke(Request $request, GeoLocationService $geo): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'lat' => ['required', 'numeric', 'between:-90,90'],
|
|
'lng' => ['required', 'numeric', 'between:-180,180'],
|
|
]);
|
|
|
|
$barangay = $geo->findBarangayByCoordinates((float) $data['lat'], (float) $data['lng']);
|
|
|
|
if (! $barangay) {
|
|
return $this->fail(
|
|
'No barangay matched the given coordinates',
|
|
['coordinates' => ['out_of_coverage']],
|
|
404,
|
|
);
|
|
}
|
|
|
|
$barangay->loadMissing('cityMunicipality.province.region');
|
|
|
|
return $this->ok([
|
|
'barangay' => new BarangayResource($barangay),
|
|
'city_municipality' => $barangay->cityMunicipality?->name,
|
|
'province' => $barangay->cityMunicipality?->province?->name,
|
|
'region' => $barangay->cityMunicipality?->province?->region?->name,
|
|
], 'Coordinates resolved');
|
|
}
|
|
}
|