Files
Verde-Web/app/Http/Controllers/Api/V1/Store/PartnerStorePublicController.php
admin 306f8fb4e8 feat(backend): customer-site API gaps + CORS
- GET /partner-stores/nearby — public, residents browse active stores
  ranked by distance via ST_Distance_Sphere; PublicPartnerStoreResource
  excludes commission rate / owner / permit (only what a buyer needs).
- GET /partner-stores/{uuid} — public details, 404 if not active.
- GET /me/collections — paginated resident QR scan history with
  optional from/to date filters.
- GET /me/upcoming-pickups — finds scheduled/in-progress trips whose
  route includes the resident's assigned drop-off point. Returns
  household_assigned: false when no household yet.
- GET /me/notifications — paginated database notifications inbox
  with unread_only filter + unread_count in meta.
- POST /me/notifications/{id}/read, POST .../mark-all-read,
  GET .../unread-count.
- config/cors.php — allow CUSTOMER_APP_URL and any EXTRA_CORS_ORIGINS
  to call the API with credentials. Same-origin admin web is
  unaffected.

202 feature tests passing.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-01 17:55:10 +08:00

43 lines
1.3 KiB
PHP

<?php
namespace App\Http\Controllers\Api\V1\Store;
use App\Http\Controllers\Api\V1\ApiController;
use App\Http\Resources\PublicPartnerStoreResource;
use App\Models\PartnerStore;
use App\Services\Store\PartnerStoreFinder;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class PartnerStorePublicController extends ApiController
{
public function nearby(Request $request, PartnerStoreFinder $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'],
]);
$stores = $finder->nearby(
(float) $data['lat'],
(float) $data['lng'],
(float) ($data['radius_km'] ?? 5.0),
(int) ($data['limit'] ?? 25),
);
return $this->ok(PublicPartnerStoreResource::collection($stores));
}
public function show(PartnerStore $store): JsonResponse
{
if ($store->status !== PartnerStore::STATUS_ACTIVE) {
return $this->fail('Store not available', null, 404);
}
$store->load(['barangay', 'inventory']);
return $this->ok(new PublicPartnerStoreResource($store));
}
}