refactor(dashboard): move price clients to app namespace and simplify data
This commit is contained in:
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Features\Dashboard\Clients;
|
namespace App\Clients;
|
||||||
|
|
||||||
use App\Features\Dashboard\Contracts\PriceClient;
|
use App\Contracts\PriceClient;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Http\Client\Factory;
|
use Illuminate\Http\Client\Factory;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Features\Dashboard\Contracts;
|
namespace App\Contracts;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Features\Dashboard\Contracts;
|
namespace App\Contracts;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
@@ -2,23 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Features\Dashboard\Data;
|
namespace App\Features\Dashboard\Data;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Spatie\LaravelData\Data;
|
use Spatie\LaravelData\Data;
|
||||||
|
|
||||||
class DashboardData extends Data
|
class DashboardData extends Data
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @property Collection<ElectricityData> $electricityHistory
|
|
||||||
* @property Collection<GasData> $gasHistory
|
|
||||||
*/
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
/** @var array<ElectricityData> */
|
public ElectricityData $electricity,
|
||||||
public Collection $electricityHistory,
|
|
||||||
public ?ElectricityData $electricityCheapest,
|
public ?ElectricityData $electricityCheapest,
|
||||||
public ?ElectricityData $electricityDurable,
|
public ?ElectricityData $electricityDurable,
|
||||||
public ?ElectricityData $electricityPriciest,
|
public ?ElectricityData $electricityPriciest,
|
||||||
/** @var array<ElectricityData> */
|
public GasData $gas,
|
||||||
public Collection $gasHistory,
|
|
||||||
public ?GasData $gasCheapest,
|
public ?GasData $gasCheapest,
|
||||||
public ?GasData $gasPriciest,
|
public ?GasData $gasPriciest,
|
||||||
) {}
|
) {}
|
||||||
|
|||||||
@@ -2,8 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Features\Dashboard\Services;
|
namespace App\Features\Dashboard\Services;
|
||||||
|
|
||||||
use App\Features\Dashboard\Contracts\PriceRepository;
|
use App\Contracts\PriceRepository;
|
||||||
use App\Features\Dashboard\Data\DashboardData;
|
use App\Features\Dashboard\Data\DashboardData;
|
||||||
|
use Carbon\Carbon;
|
||||||
|
|
||||||
class DashboardService
|
class DashboardService
|
||||||
{
|
{
|
||||||
@@ -13,21 +14,26 @@ class DashboardService
|
|||||||
|
|
||||||
public function getDashboardData(): DashboardData
|
public function getDashboardData(): DashboardData
|
||||||
{
|
{
|
||||||
|
$now = Carbon::now();
|
||||||
|
|
||||||
$electricity = $this->repository->retrieveElectricity();
|
$electricity = $this->repository->retrieveElectricity();
|
||||||
$eCheapest = $electricity->min('total_price_tax_included');
|
|
||||||
$eDurable = $electricity->min('sustainability_score');
|
$eNow = $electricity->whereBetween('startDate', [$now->copy()->subHour(), $now])->first();
|
||||||
$ePriciest = $electricity->max('total_price_tax_included');
|
$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();
|
$gas = $this->repository->retrieveGas();
|
||||||
$gCheapest = $gas->min('total_price_tax_included');
|
$gNow = $gas->whereBetween('startDate', [$now->copy()->setHour(0), $now])->first();
|
||||||
$gPriciest = $gas->min('total_price_tax_included');
|
$gCheapest = $gas->where('totalPriceTaxIncluded', $gas->min('totalPriceTaxIncluded'))->first();
|
||||||
|
$gPriciest = $gas->where('totalPriceTaxIncluded', $gas->min('totalPriceTaxIncluded'))->first();
|
||||||
|
|
||||||
return new DashboardData(
|
return new DashboardData(
|
||||||
$electricity,
|
$eNow,
|
||||||
$eCheapest,
|
$eCheapest,
|
||||||
$eDurable,
|
$eDurable,
|
||||||
$ePriciest,
|
$ePriciest,
|
||||||
$gas,
|
$gNow,
|
||||||
$gCheapest,
|
$gCheapest,
|
||||||
$gPriciest
|
$gPriciest
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -2,10 +2,10 @@
|
|||||||
|
|
||||||
namespace App\Providers;
|
namespace App\Providers;
|
||||||
|
|
||||||
use App\Features\Dashboard\Clients\ZonneplanPriceClient;
|
use App\Clients\ZonneplanPriceClient;
|
||||||
use App\Features\Dashboard\Contracts\PriceClient;
|
use App\Contracts\PriceClient;
|
||||||
use App\Features\Dashboard\Contracts\PriceRepository;
|
use App\Contracts\PriceRepository;
|
||||||
use App\Features\Dashboard\Repositories\ZonneplanPriceRepository;
|
use App\Repositories\ZonneplanPriceRepository;
|
||||||
use Carbon\CarbonImmutable;
|
use Carbon\CarbonImmutable;
|
||||||
use Illuminate\Support\Facades\Date;
|
use Illuminate\Support\Facades\Date;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|||||||
+3
-3
@@ -1,9 +1,9 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Features\Dashboard\Repositories;
|
namespace App\Repositories;
|
||||||
|
|
||||||
use App\Features\Dashboard\Contracts\PriceClient;
|
use App\Contracts\PriceClient;
|
||||||
use App\Features\Dashboard\Contracts\PriceRepository as ContractsPriceRepository;
|
use App\Contracts\PriceRepository as ContractsPriceRepository;
|
||||||
use App\Features\Dashboard\Data\ElectricityData;
|
use App\Features\Dashboard\Data\ElectricityData;
|
||||||
use App\Features\Dashboard\Data\GasData;
|
use App\Features\Dashboard\Data\GasData;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import i18next from 'i18next';
|
import i18next from 'i18next';
|
||||||
import translations from './translations';
|
import resources from './translations';
|
||||||
|
|
||||||
await i18next.init({
|
await i18next.init(() => ({
|
||||||
lng: 'nl',
|
lng: 'nl',
|
||||||
resources: translations,
|
resources,
|
||||||
});
|
}));
|
||||||
|
|
||||||
export default i18next;
|
export default i18next;
|
||||||
|
|||||||
Reference in New Issue
Block a user