- 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>
57 lines
2.0 KiB
PHP
57 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api\V1\Me;
|
|
|
|
use App\Http\Controllers\Api\V1\ApiController;
|
|
use App\Models\CollectionLog;
|
|
use App\Models\Household;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
class MyCollectionsController extends ApiController
|
|
{
|
|
/**
|
|
* Resident's QR collection history. Filters by date range.
|
|
*/
|
|
public function index(Request $request): JsonResponse
|
|
{
|
|
$data = $request->validate([
|
|
'from' => ['nullable', 'date'],
|
|
'to' => ['nullable', 'date'],
|
|
'per_page' => ['nullable', 'integer', 'min:1', 'max:100'],
|
|
]);
|
|
|
|
$household = Household::where('head_user_id', $request->user()->id)->first();
|
|
if (! $household) {
|
|
return $this->ok([], 'No household yet');
|
|
}
|
|
|
|
$perPage = (int) ($data['per_page'] ?? 25);
|
|
|
|
$logs = CollectionLog::query()
|
|
->with(['qrCode:id,serial', 'dropOffPoint:id,name,uuid'])
|
|
->where('household_id', $household->id)
|
|
->where('verification_status', CollectionLog::STATUS_VALID)
|
|
->when($data['from'] ?? null, fn ($q, $from) => $q->where('scanned_at', '>=', \Carbon\Carbon::parse($from)->startOfDay()))
|
|
->when($data['to'] ?? null, fn ($q, $to) => $q->where('scanned_at', '<=', \Carbon\Carbon::parse($to)->endOfDay()))
|
|
->orderByDesc('scanned_at')
|
|
->paginate($perPage);
|
|
|
|
$items = $logs->getCollection()->map(fn (CollectionLog $l) => [
|
|
'id' => $l->id,
|
|
'serial' => $l->qrCode?->serial,
|
|
'scanned_at' => $l->scanned_at?->toIso8601String(),
|
|
'weight_kg' => $l->weight_kg,
|
|
'waste_type' => $l->waste_type,
|
|
'drop_off_point' => $l->dropOffPoint?->name,
|
|
])->all();
|
|
|
|
return $this->ok($items, null, [
|
|
'page' => $logs->currentPage(),
|
|
'per_page' => $logs->perPage(),
|
|
'total' => $logs->total(),
|
|
'last_page' => $logs->lastPage(),
|
|
]);
|
|
}
|
|
}
|