refactor(dashboard,history): replace ViewModels with Pinia stores and improve backend
This commit is contained in:
@@ -14,19 +14,25 @@ class DashboardService
|
||||
|
||||
public function getDashboardData(): DashboardData
|
||||
{
|
||||
$electricity = $this->repository->retrieveElectricity();
|
||||
$gas = $this->repository->retrieveGas();
|
||||
|
||||
$now = Carbon::now();
|
||||
|
||||
$electricity = $this->repository->retrieveElectricity();
|
||||
|
||||
$eNow = $electricity->whereBetween('startDate', [$now->copy()->subHour(), $now])->first();
|
||||
$eNow = $electricity->first(
|
||||
fn ($item) => $item->startDate instanceof Carbon
|
||||
&& $item->startDate->gte($now->copy()->subHour())
|
||||
&& $item->startDate->lte($now)
|
||||
);
|
||||
$eCheapest = $electricity->where('totalPriceTaxIncluded', $electricity->min('totalPriceTaxIncluded'))->first();
|
||||
$eDurable = $electricity->where('sustainabilityScore', $electricity->max('sustainabilityScore'))->first();
|
||||
$ePriciest = $electricity->where('totalPriceTaxIncluded', $electricity->max('totalPriceTaxIncluded'))->first();
|
||||
|
||||
$gas = $this->repository->retrieveGas();
|
||||
$gNow = $gas->whereBetween('startDate', [$now->copy()->setHour(0), $now])->first();
|
||||
$gCheapest = $gas->where('totalPriceTaxIncluded', $gas->min('totalPriceTaxIncluded'))->first();
|
||||
$gPriciest = $gas->where('totalPriceTaxIncluded', $gas->max('totalPriceTaxIncluded'))->first();
|
||||
$gNow = $gas->first(
|
||||
fn ($item) => $item->startDate instanceof Carbon
|
||||
&& $item->startDate->gte($now->copy()->startOfDay())
|
||||
&& $item->startDate->lte($now)
|
||||
);
|
||||
|
||||
return new DashboardData(
|
||||
$eNow,
|
||||
@@ -34,8 +40,6 @@ class DashboardService
|
||||
$eDurable,
|
||||
$ePriciest,
|
||||
$gNow,
|
||||
$gCheapest,
|
||||
$gPriciest
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user