feat(backend): complete Module 6 (dumpsites + geofence)
dumpsites table with both coordinates POINT and boundary_polygon
POLYGON (SRID 4326). Admin CRUD accepts boundary as a list of {lat,lng}
points; ring is auto-closed. Dumpsite::containsPoint() runs ST_Contains
for geofence checks (Module 10 will fire arrived_at_dumpsite from this).
dumpsite_releases schema in place — trip_id stays nullable bigint until
Module 10 adds the FK.
109 feature tests passing.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
44
app/Http/Resources/DumpsiteResource.php
Normal file
44
app/Http/Resources/DumpsiteResource.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class DumpsiteResource extends JsonResource
|
||||
{
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
$boundaryPoints = null;
|
||||
if ($this->boundary_polygon) {
|
||||
$rings = $this->boundary_polygon->getGeometries();
|
||||
$ring = $rings->first();
|
||||
if ($ring) {
|
||||
$boundaryPoints = $ring->getGeometries()
|
||||
->map(fn ($p) => ['lat' => $p->latitude, 'lng' => $p->longitude])
|
||||
->all();
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => $this->uuid,
|
||||
'name' => $this->name,
|
||||
'code' => $this->code,
|
||||
'address_line' => $this->address_line,
|
||||
'coordinates' => $this->coordinates ? [
|
||||
'lat' => $this->coordinates->latitude,
|
||||
'lng' => $this->coordinates->longitude,
|
||||
] : null,
|
||||
'boundary_polygon' => $boundaryPoints,
|
||||
'accepted_waste_types' => $this->accepted_waste_types,
|
||||
'operating_hours' => $this->operating_hours,
|
||||
'capacity_tons' => $this->capacity_tons,
|
||||
'permit_number' => $this->permit_number,
|
||||
'status' => $this->status,
|
||||
'contact_person' => $this->contact_person,
|
||||
'contact_phone' => $this->contact_phone,
|
||||
'city_municipality' => CityMunicipalityResource::make($this->whenLoaded('cityMunicipality')),
|
||||
'created_at' => $this->created_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user