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
@@ -2,8 +2,9 @@
namespace App\Features\Dashboard\Services;
use App\Features\Dashboard\Contracts\PriceRepository;
use App\Contracts\PriceRepository;
use App\Features\Dashboard\Data\DashboardData;
use Carbon\Carbon;
class DashboardService
{
@@ -13,21 +14,26 @@ class DashboardService
public function getDashboardData(): DashboardData
{
$now = Carbon::now();
$electricity = $this->repository->retrieveElectricity();
$eCheapest = $electricity->min('total_price_tax_included');
$eDurable = $electricity->min('sustainability_score');
$ePriciest = $electricity->max('total_price_tax_included');
$eNow = $electricity->whereBetween('startDate', [$now->copy()->subHour(), $now])->first();
$eCheapest = $electricity->where('totalPriceTaxIncluded', $electricity->min('totalPriceTaxIncluded'))->first();
$eDurable = $electricity->where('sustainabilityScore', $electricity->min('sustainabilityScore'))->first();
$ePriciest = $electricity->where('totalPriceTaxIncluded', $electricity->max('totalPriceTaxIncluded'))->first();
$gas = $this->repository->retrieveGas();
$gCheapest = $gas->min('total_price_tax_included');
$gPriciest = $gas->min('total_price_tax_included');
$gNow = $gas->whereBetween('startDate', [$now->copy()->setHour(0), $now])->first();
$gCheapest = $gas->where('totalPriceTaxIncluded', $gas->min('totalPriceTaxIncluded'))->first();
$gPriciest = $gas->where('totalPriceTaxIncluded', $gas->min('totalPriceTaxIncluded'))->first();
return new DashboardData(
$electricity,
$eNow,
$eCheapest,
$eDurable,
$ePriciest,
$gas,
$gNow,
$gCheapest,
$gPriciest
);