refactor(dashboard): move price clients to app namespace and simplify data
This commit is contained in:
@@ -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
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user