Deprecate AccountingSeries for AccountingBalancePoint

This commit is contained in:
2025-02-11 12:22:29 +01:00
parent 954bf8e7c1
commit fbbebbc758
4 changed files with 1 additions and 146 deletions
@@ -1,54 +0,0 @@
<?php
namespace App\ApiResource\Accounting;
use ApiPlatform\Metadata as API;
use App\Dto\AccountingSeriesDto;
use App\State\Accounting\AccountingSeriesStateProcessor;
/**
* An AccountingSeries displays plottable, aggregated balance data over a time range for a given Accounting.\
* \
* AccountingSeries are calculated in real-time for each request from the available data for the Accountings,
* each data point is a Money object representing the aggregated balance of the Accounting at that point in the series.\
* \
* Data points are relative to the series unit of time,
* each point represents a lapse of `unit` over the `startDate`.
*/
#[API\ApiResource(shortName: 'AccountingSeries')]
#[API\Post(
input: AccountingSeriesDto::class,
processor: AccountingSeriesStateProcessor::class
)]
class AccountingSeriesApiResource
{
/**
* The source Accounting for the data series.
*/
public AccountingApiResource $accounting;
/**
* The start date for the data series.
*/
public \DateTimeInterface $start;
/**
* The time unit for each data point in the series.
*/
public string $interval;
/**
* The end date for the data series. Inclusive.
*/
public \DateTimeInterface $end;
/**
* The number of data points in the series.
*/
public int $length;
/**
* @var array<int, \App\Entity\Money>
*/
public array $data;
}
-41
View File
@@ -1,41 +0,0 @@
<?php
namespace App\Dto;
use ApiPlatform\Metadata\ApiProperty;
use App\ApiResource\Accounting\AccountingApiResource;
use Symfony\Component\Validator\Constraints as Assert;
class AccountingSeriesDto
{
/**
* The source Accounting for the data series.
*/
#[Assert\NotBlank()]
public AccountingApiResource $accounting;
/**
* The start date for the data series.
*/
#[Assert\NotBlank()]
public \DateTimeInterface $start;
/**
* The time unit for each data point in the series,
* expressed as an integer followed by a time unit initial.
*/
#[Assert\Choice(['24H'])]
public string $interval = '24H';
/**
* The end date for the data series. Inclusive.
*/
#[Assert\LessThanOrEqual('now')]
#[ApiProperty(default: 'now')]
public ?\DateTimeInterface $end = null;
public function __construct()
{
$this->end ??= new \DateTimeImmutable('now');
}
}
@@ -25,9 +25,7 @@ class AccountingBalancePointStateProvider implements ProviderInterface
$accounting = $this->getAccounting($parameters);
$period = $this->buildPeriod($parameters);
$points = $this->accountingService->calcBalancePoints($accounting, $period);
dd($points);
return $this->accountingService->calcBalancePoints($accounting, $period);
}
private function getAccounting(Parameters $parameters): Accounting
@@ -1,48 +0,0 @@
<?php
namespace App\State\Accounting;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\ApiResource\Accounting\AccountingSeriesApiResource;
use App\Dto\AccountingSerieDto;
use App\Entity\Accounting\Accounting;
use App\Mapping\AutoMapper;
use App\Service\AccountingService;
class AccountingSeriesStateProcessor implements ProcessorInterface
{
public function __construct(
private AutoMapper $autoMapper,
private AccountingService $accountingService,
) {}
/**
* @param AccountingSerieDto $data
*
* @return AccountingSeriesApiResource
*/
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = [])
{
/** @var Accounting */
$accounting = $this->autoMapper->map($data->accounting, Accounting::class);
$points = $this->accountingService->calcBalanceSeries(
$accounting,
new \DatePeriod(
$data->start,
new \DateInterval(\sprintf('PT%s', $data->interval)),
$data->end,
\DatePeriod::INCLUDE_END_DATE
)
);
/** @var AccountingSeriesApiResource */
$series = $this->autoMapper->map($data, AccountingSeriesApiResource::class);
$series->data = $points;
$series->length = \count($points);
return $series;
}
}