From b2cc3ee0ff1c74cc14236781148fa991f3581a8e Mon Sep 17 00:00:00 2001 From: Ovidiu U Date: Sat, 4 Apr 2026 14:23:57 +0100 Subject: [PATCH] feat: add BrentPriceResource with 30-day line chart widget Co-Authored-By: Claude Sonnet 4.6 --- app/Filament/Resources/BrentPriceResource.php | 46 +++++++++++++++++++ .../Pages/ListBrentPrices.php | 24 ++++++++++ .../Widgets/BrentPriceChartWidget.php | 40 ++++++++++++++++ .../Feature/Admin/BrentPriceResourceTest.php | 22 +++++++++ 4 files changed, 132 insertions(+) create mode 100644 app/Filament/Resources/BrentPriceResource.php create mode 100644 app/Filament/Resources/BrentPriceResource/Pages/ListBrentPrices.php create mode 100644 app/Filament/Widgets/BrentPriceChartWidget.php create mode 100644 tests/Feature/Admin/BrentPriceResourceTest.php diff --git a/app/Filament/Resources/BrentPriceResource.php b/app/Filament/Resources/BrentPriceResource.php new file mode 100644 index 0000000..d321e05 --- /dev/null +++ b/app/Filament/Resources/BrentPriceResource.php @@ -0,0 +1,46 @@ +columns([ + TextColumn::make('date') + ->date('d M Y') + ->sortable(), + TextColumn::make('price_usd') + ->label('Price (USD/barrel)') + ->numeric(2) + ->sortable(), + ]) + ->defaultSort('date', 'desc') + ->recordActions([]) + ->filters([]); + } + + public static function getPages(): array + { + return [ + 'index' => ListBrentPrices::route('/'), + ]; + } +} diff --git a/app/Filament/Resources/BrentPriceResource/Pages/ListBrentPrices.php b/app/Filament/Resources/BrentPriceResource/Pages/ListBrentPrices.php new file mode 100644 index 0000000..ad2ffcb --- /dev/null +++ b/app/Filament/Resources/BrentPriceResource/Pages/ListBrentPrices.php @@ -0,0 +1,24 @@ +where('date', '>=', now()->subDays(30)->toDateString()) + ->get(); + + return [ + 'datasets' => [ + [ + 'label' => 'USD/barrel', + 'data' => $prices->pluck('price_usd')->map(fn ($p) => (float) $p)->toArray(), + 'borderColor' => '#f59e0b', + 'fill' => false, + 'tension' => 0.3, + ], + ], + 'labels' => $prices->pluck('date') + ->map(fn ($d) => $d->format('d M')) + ->toArray(), + ]; + } + + protected function getType(): string + { + return 'line'; + } +} diff --git a/tests/Feature/Admin/BrentPriceResourceTest.php b/tests/Feature/Admin/BrentPriceResourceTest.php new file mode 100644 index 0000000..17811c6 --- /dev/null +++ b/tests/Feature/Admin/BrentPriceResourceTest.php @@ -0,0 +1,22 @@ +admin = User::factory()->admin()->create(); + $this->actingAs($this->admin); +}); + +it('renders the brent price list', function () { + $prices = BrentPrice::factory()->count(3)->create(); + + Livewire::test(ListBrentPrices::class) + ->assertOk() + ->assertCanSeeTableRecords($prices); +});