feat(history): add energy price history feature
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\History\Controllers;
|
||||
|
||||
use App\Features\History\Data\HistoryData;
|
||||
use App\Features\History\Requests\HistoryRequest;
|
||||
use App\Features\History\Services\HistoryService;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class HistoryController extends Controller
|
||||
{
|
||||
public function index(HistoryRequest $request, HistoryService $historyService): HistoryData
|
||||
{
|
||||
$date = Carbon::now();
|
||||
|
||||
if ($request->date) {
|
||||
$date = $request->date;
|
||||
}
|
||||
|
||||
return $historyService->getHistoryData($date);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\History\Data;
|
||||
|
||||
use App\Data\ElectricityData;
|
||||
use App\Data\GasData;
|
||||
use Illuminate\Support\Collection;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class HistoryData extends Data
|
||||
{
|
||||
/**
|
||||
* @property Collection<ElectricityData> $electricity
|
||||
* @property Collection<GasData> $gas
|
||||
*/
|
||||
public function __construct(
|
||||
public Collection $electricity,
|
||||
public Collection $gas,
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Features\History\Requests;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Spatie\LaravelData\Data;
|
||||
|
||||
class HistoryRequest extends Data
|
||||
{
|
||||
public function __construct(
|
||||
public ?Carbon $date
|
||||
) {}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
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;
|
||||
|
||||
class HistoryService
|
||||
{
|
||||
public function __construct(
|
||||
public PriceRepository $repository
|
||||
) {}
|
||||
|
||||
public function getHistoryData(Carbon $date): HistoryData
|
||||
{
|
||||
$electricity = ElectricityData::collect($this->repository->retrieveElectricityForDate($date));
|
||||
$gas = GasData::collect($this->repository->retrieveGasForDate($date));
|
||||
|
||||
return new HistoryData($electricity, $gas);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user