Create charge state processor
This commit is contained in:
@@ -6,11 +6,13 @@ use ApiPlatform\Doctrine\Orm\Filter;
|
||||
use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\Accounting\AccountingApiResource;
|
||||
use App\Dto\Gateway\ChargeUpdateDto;
|
||||
use App\Entity\Gateway\Charge;
|
||||
use App\Entity\Money;
|
||||
use App\Gateway\ChargeStatus;
|
||||
use App\Gateway\ChargeType;
|
||||
use App\State\ApiResourceStateProvider;
|
||||
use App\State\Gateway\ChargeStateProcessor;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
@@ -23,7 +25,10 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
)]
|
||||
#[API\Get()]
|
||||
#[API\GetCollection(security: "is_granted('IS_AUTHENTICATED_FULLY')")]
|
||||
#[API\Patch()]
|
||||
#[API\Patch(
|
||||
input: ChargeUpdateDto::class,
|
||||
processor: ChargeStateProcessor::class,
|
||||
)]
|
||||
class ChargeApiResource
|
||||
{
|
||||
#[API\ApiProperty(writable: false, identifier: true)]
|
||||
@@ -78,5 +83,5 @@ class ChargeApiResource
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[API\ApiFilter(Filter\SearchFilter::class, properties: ['status' => 'exact'])]
|
||||
public ChargeStatus $status;
|
||||
public ChargeStatus $status = ChargeStatus::Pending;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Dto\Gateway;
|
||||
|
||||
use App\Gateway\ChargeStatus;
|
||||
use App\Gateway\ChargeType;
|
||||
|
||||
class ChargeUpdateDto
|
||||
{
|
||||
public ChargeType $type;
|
||||
|
||||
public string $title;
|
||||
|
||||
public string $description;
|
||||
|
||||
public ChargeStatus $status;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
namespace App\State\Gateway;
|
||||
|
||||
use ApiPlatform\Doctrine\Common\State\PersistProcessor;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\ApiResource\Gateway\ChargeApiResource;
|
||||
use App\Dto\Gateway\ChargeUpdateDto;
|
||||
use App\Entity\Gateway\Charge;
|
||||
use App\Mapping\AutoMapper;
|
||||
use App\State\EntityStateProcessor;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
||||
|
||||
class ChargeStateProcessor implements ProcessorInterface
|
||||
{
|
||||
public function __construct(
|
||||
private EntityStateProcessor $entityStateProcessor,
|
||||
#[Autowire(service: PersistProcessor::class)]
|
||||
private ProcessorInterface $innerProcessor,
|
||||
#[Autowire(service: AutoMapper::class)]
|
||||
private AutoMapper $autoMapper,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param ChargeUpdateDto $data
|
||||
* @param array{id: int} $uriVariables
|
||||
*/
|
||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ?ChargeApiResource
|
||||
{
|
||||
// if ($data instanceof ChargeUpdateDto) {
|
||||
// $data = $this->autoMapper->map($uriVariables, $data);
|
||||
|
||||
// /** @var Charge */
|
||||
// $charge = $this->autoMapper->map($data, Charge::class);
|
||||
// }
|
||||
|
||||
// $charge = $this->entityStateProcessor->process($charge, $operation, $uriVariables, $context);
|
||||
$charge = $this->entityStateProcessor->process($data, $operation, $uriVariables, $context);
|
||||
|
||||
if ($charge === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->autoMapper->map($charge, ChargeApiResource::class);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user