40 lines
1.2 KiB
PHP
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:25000'],
|
|
'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));
|
|
}
|
|
}
|