refactor(dashboard): move price clients to app namespace and simplify data
This commit is contained in:
+2
-2
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Dashboard\Clients;
|
||||
namespace App\Clients;
|
||||
|
||||
use App\Features\Dashboard\Contracts\PriceClient;
|
||||
use App\Contracts\PriceClient;
|
||||
use Exception;
|
||||
use Illuminate\Http\Client\Factory;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Dashboard\Contracts;
|
||||
namespace App\Contracts;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Dashboard\Contracts;
|
||||
namespace App\Contracts;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
@@ -2,23 +2,16 @@
|
||||
|
||||
namespace App\Features\Dashboard\Data;
|
||||
|
||||
use Illuminate\Support\Collection;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class DashboardData extends Data
|
||||
{
|
||||
/**
|
||||
* @property Collection<ElectricityData> $electricityHistory
|
||||
* @property Collection<GasData> $gasHistory
|
||||
*/
|
||||
public function __construct(
|
||||
/** @var array<ElectricityData> */
|
||||
public Collection $electricityHistory,
|
||||
public ElectricityData $electricity,
|
||||
public ?ElectricityData $electricityCheapest,
|
||||
public ?ElectricityData $electricityDurable,
|
||||
public ?ElectricityData $electricityPriciest,
|
||||
/** @var array<ElectricityData> */
|
||||
public Collection $gasHistory,
|
||||
public GasData $gas,
|
||||
public ?GasData $gasCheapest,
|
||||
public ?GasData $gasPriciest,
|
||||
) {}
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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;
|
||||
|
||||
+3
-3
@@ -1,9 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\Dashboard\Repositories;
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Features\Dashboard\Contracts\PriceClient;
|
||||
use App\Features\Dashboard\Contracts\PriceRepository as ContractsPriceRepository;
|
||||
use App\Contracts\PriceClient;
|
||||
use App\Contracts\PriceRepository as ContractsPriceRepository;
|
||||
use App\Features\Dashboard\Data\ElectricityData;
|
||||
use App\Features\Dashboard\Data\GasData;
|
||||
use Illuminate\Support\Collection;
|
||||
@@ -1,9 +1,9 @@
|
||||
import i18next from 'i18next';
|
||||
import translations from './translations';
|
||||
import resources from './translations';
|
||||
|
||||
await i18next.init({
|
||||
await i18next.init(() => ({
|
||||
lng: 'nl',
|
||||
resources: translations,
|
||||
});
|
||||
resources,
|
||||
}));
|
||||
|
||||
export default i18next;
|
||||
|
||||
Reference in New Issue
Block a user