refactor(dashboard): move price clients to app namespace and simplify data

This commit is contained in:
2026-08-01 21:55:23 +02:00
parent 69f214ade3
commit 0fa648f833
8 changed files with 31 additions and 32 deletions
+61
View File
@@ -0,0 +1,61 @@
<?php
namespace App\Clients;
use App\Contracts\PriceClient;
use Exception;
use Illuminate\Http\Client\Factory;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Log;
use Throwable;
class ZonneplanPriceClient implements PriceClient
{
public function __construct(
private readonly Factory $http,
) {}
public function getElectricityPrices(): Collection
{
return collect($this->get('/energy-prices/electricity/upcoming'));
}
public function getGasPrices(): Collection
{
return collect($this->get('/energy-prices/gas/upcoming'));
}
/** @return array<int, array<string, mixed>> */
private function get(string $path): array
{
try {
$response = $this->http
->baseUrl(config('api.baseurl'))
->withQueryParameters([
'secret' => config('api.key'),
])
->timeout(10)
->retry(2, 100)
->get($path);
$response->throw();
Log::info('Zonneplan API opgehaald', [
'path' => $path,
'status' => $response->status(),
]);
return $response->json('data', []);
} catch (Throwable $e) {
Log::error('Zonneplan API aanroep mislukt', [
'path' => $path,
'message' => $e->getMessage(),
]);
throw new Exception(
"Kon energieprijzen niet ophalen voor {$path}",
previous: $e,
);
}
}
}