diff --git a/app/Features/Dashboard/Clients/ZonneplanPriceClient.php b/app/Clients/ZonneplanPriceClient.php similarity index 94% rename from app/Features/Dashboard/Clients/ZonneplanPriceClient.php rename to app/Clients/ZonneplanPriceClient.php index dbaabb9..11a959b 100644 --- a/app/Features/Dashboard/Clients/ZonneplanPriceClient.php +++ b/app/Clients/ZonneplanPriceClient.php @@ -1,8 +1,8 @@ $electricityHistory - * @property Collection $gasHistory - */ public function __construct( - /** @var array */ - public Collection $electricityHistory, + public ElectricityData $electricity, public ?ElectricityData $electricityCheapest, public ?ElectricityData $electricityDurable, public ?ElectricityData $electricityPriciest, - /** @var array */ - public Collection $gasHistory, + public GasData $gas, public ?GasData $gasCheapest, public ?GasData $gasPriciest, ) {} diff --git a/app/Features/Dashboard/Services/DashboardService.php b/app/Features/Dashboard/Services/DashboardService.php index e427f32..a932e2b 100644 --- a/app/Features/Dashboard/Services/DashboardService.php +++ b/app/Features/Dashboard/Services/DashboardService.php @@ -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 ); diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 03e020d..4e6f5eb 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -2,10 +2,10 @@ namespace App\Providers; -use App\Features\Dashboard\Clients\ZonneplanPriceClient; -use App\Features\Dashboard\Contracts\PriceClient; -use App\Features\Dashboard\Contracts\PriceRepository; -use App\Features\Dashboard\Repositories\ZonneplanPriceRepository; +use App\Clients\ZonneplanPriceClient; +use App\Contracts\PriceClient; +use App\Contracts\PriceRepository; +use App\Repositories\ZonneplanPriceRepository; use Carbon\CarbonImmutable; use Illuminate\Support\Facades\Date; use Illuminate\Support\Facades\DB; diff --git a/app/Features/Dashboard/Repositories/ZonneplanPriceRepository.php b/app/Repositories/ZonneplanPriceRepository.php similarity index 81% rename from app/Features/Dashboard/Repositories/ZonneplanPriceRepository.php rename to app/Repositories/ZonneplanPriceRepository.php index d3a43c6..ce33adb 100644 --- a/app/Features/Dashboard/Repositories/ZonneplanPriceRepository.php +++ b/app/Repositories/ZonneplanPriceRepository.php @@ -1,9 +1,9 @@ ({ lng: 'nl', - resources: translations, -}); + resources, +})); export default i18next;