Files
Verde-Web/app/Http/Controllers/Api/V1/DropOff/DropOffPointController.php
admin 1150a518e8 feat(backend): complete Module 5 (drop-off points + auto-assign)
drop_off_points (with SPATIAL INDEX on coordinates) +
drop_off_capacity_logs. Public nearby query via ST_Distance_Sphere
returns DOPs sorted by distance with distance_meters in payload.
Admin CRUD plus capacity-log endpoint. Household creation auto-assigns
to the nearest active DOP within 25km; resident can re-run the lookup
via POST /households/{uuid}/reassign-drop-off.

97 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-30 00:11:22 +08:00

40 lines
1.2 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1\DropOff;
use App\Http\Controllers\Api\V1\ApiController;
use App\Http\Resources\DropOffPointResource;
use App\Models\DropOffPoint;
use App\Services\DropOff\DropOffPointFinder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class DropOffPointController extends ApiController
{
public function nearby(Request $request, DropOffPointFinder $finder): JsonResponse
{
$data = $request->validate([
'lat' => ['required', 'numeric', 'between:-90,90'],
'lng' => ['required', 'numeric', 'between:-180,180'],
'radius_km' => ['nullable', 'numeric', 'min:0.1', 'max:50'],
'limit' => ['nullable', 'integer', 'min:1', 'max:50'],
]);
$points = $finder->nearby(
(float) $data['lat'],
(float) $data['lng'],
(float) ($data['radius_km'] ?? 5.0),
(int) ($data['limit'] ?? 25),
);
return $this->ok(DropOffPointResource::collection($points));
}
public function show(DropOffPoint $dropOffPoint): JsonResponse
{
$dropOffPoint->load('barangay.cityMunicipality');
return $this->ok(new DropOffPointResource($dropOffPoint));
}
}