refactor(dashboard,history): replace ViewModels with Pinia stores and improve backend
This commit is contained in:
@@ -9,12 +9,10 @@ use Spatie\LaravelData\Data;
|
||||
class DashboardData extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public ElectricityData $electricity,
|
||||
public ?ElectricityData $electricity,
|
||||
public ?ElectricityData $electricityCheapest,
|
||||
public ?ElectricityData $electricityDurable,
|
||||
public ?ElectricityData $electricityPriciest,
|
||||
public GasData $gas,
|
||||
public ?GasData $gasCheapest,
|
||||
public ?GasData $gasPriciest,
|
||||
public ?GasData $gas,
|
||||
) {}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace App\Features\History\Services;
|
||||
|
||||
use App\Contracts\PriceRepository;
|
||||
use App\Data\ElectricityData;
|
||||
use App\Data\GasData;
|
||||
use App\Features\History\Data\HistoryData;
|
||||
use Carbon\Carbon;
|
||||
|
||||
@@ -16,9 +14,12 @@ class HistoryService
|
||||
|
||||
public function getHistoryData(Carbon $date): HistoryData
|
||||
{
|
||||
$electricity = ElectricityData::collect($this->repository->retrieveElectricityForDate($date));
|
||||
$gas = GasData::collect($this->repository->retrieveGasForDate($date));
|
||||
$electricity = $this->repository->retrieveElectricityForDate($date);
|
||||
$gas = $this->repository->retrieveGasForDate($date);
|
||||
|
||||
return new HistoryData($electricity, $gas);
|
||||
return new HistoryData(
|
||||
electricity: $electricity,
|
||||
gas: $gas
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user