Files
Verde-Web/database/seeders/SampleDropOffPointsSeeder.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

64 lines
2.8 KiB
PHP

<?php
namespace Database\Seeders;
use App\Models\Barangay;
use App\Models\DropOffPoint;
use Illuminate\Database\Seeder;
use MatanYadaev\EloquentSpatial\Objects\Point;
/**
* A handful of DOPs around the SamplePsgcSeeder barangays so that
* `GET /drop-off-points/nearby` and household auto-assign return real
* results in development.
*/
class SampleDropOffPointsSeeder extends Seeder
{
public function run(): void
{
$bagongPagAsa = Barangay::where('code', 'QC-BPA')->first();
$diliman = Barangay::where('code', 'QC-DLM')->first();
$commonwealth = Barangay::where('code', 'QC-CMW')->first();
$ermita = Barangay::where('code', 'MNL-ERM')->first();
$poblacion = Barangay::where('code', 'MKT-PBL')->first();
$hours = [
'mon' => ['open' => '06:00', 'close' => '18:00'],
'tue' => ['open' => '06:00', 'close' => '18:00'],
'wed' => ['open' => '06:00', 'close' => '18:00'],
'thu' => ['open' => '06:00', 'close' => '18:00'],
'fri' => ['open' => '06:00', 'close' => '18:00'],
'sat' => ['open' => '07:00', 'close' => '15:00'],
'sun' => null,
];
$waste = ['general', 'recyclable', 'biodegradable'];
$dops = [
['code' => 'DOP-QC-BPA-01', 'name' => 'Bagong Pag-asa Plaza', 'barangay' => $bagongPagAsa, 'lat' => 14.6493, 'lng' => 121.0386, 'capacity' => 800],
['code' => 'DOP-QC-DLM-01', 'name' => 'Diliman Triangle DOP', 'barangay' => $diliman, 'lat' => 14.6539, 'lng' => 121.0685, 'capacity' => 1200],
['code' => 'DOP-QC-CMW-01', 'name' => 'Commonwealth Market DOP', 'barangay' => $commonwealth, 'lat' => 14.6970, 'lng' => 121.0780, 'capacity' => 1500],
['code' => 'DOP-MNL-ERM-01', 'name' => 'Ermita Drop-off Center', 'barangay' => $ermita, 'lat' => 14.5824, 'lng' => 120.9831, 'capacity' => 600],
['code' => 'DOP-MKT-PBL-01', 'name' => 'Poblacion Eco Hub', 'barangay' => $poblacion, 'lat' => 14.5648, 'lng' => 121.0306, 'capacity' => 700],
];
foreach ($dops as $d) {
DropOffPoint::updateOrCreate(
['code' => $d['code']],
[
'name' => $d['name'],
'barangay_id' => $d['barangay']?->id,
'coordinates' => new Point($d['lat'], $d['lng'], 4326),
'address_line' => $d['name'].' (sample)',
'capacity_kg' => $d['capacity'],
'operating_hours' => $hours,
'accepted_waste_types' => $waste,
'status' => DropOffPoint::STATUS_ACTIVE,
'contact_person' => 'LGU Caretaker',
'contact_phone' => '+63281000000',
],
);
}
}
}