refactor: extract Brent price sources into dedicated classes

OilPriceService no longer inlines per-provider fetch/transform/error logic.
EIA and FRED are now their own classes with a common shape; the service
just iterates and upserts the first successful result.
This commit is contained in:
Ovidiu U
2026-04-14 16:29:52 +01:00
parent a7ee9f4557
commit 1a0381265e
4 changed files with 139 additions and 114 deletions

View File

@@ -5,6 +5,8 @@ use App\Enums\TrendDirection;
use App\Models\BrentPrice;
use App\Models\PricePrediction;
use App\Services\ApiLogger;
use App\Services\BrentPriceSources\EiaBrentPriceSource;
use App\Services\BrentPriceSources\FredBrentPriceSource;
use App\Services\LlmPrediction\OilPredictionProvider;
use App\Services\OilPriceService;
use Illuminate\Foundation\Testing\RefreshDatabase;
@@ -15,7 +17,12 @@ uses(RefreshDatabase::class);
beforeEach(function (): void {
Http::preventStrayRequests();
$this->provider = Mockery::mock(OilPredictionProvider::class);
$this->service = new OilPriceService(new ApiLogger, $this->provider);
$apiLogger = new ApiLogger;
$this->service = new OilPriceService(
$this->provider,
new EiaBrentPriceSource($apiLogger),
new FredBrentPriceSource($apiLogger),
);
});
// --- fetchBrentPrices ---