Skip to content

Commit

Permalink
Update gateway mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
subiabre committed Dec 9, 2024
1 parent 4735512 commit 88ca27c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 24 deletions.
18 changes: 0 additions & 18 deletions src/Mapping/Gateway/GatewayMapper.php

This file was deleted.

20 changes: 14 additions & 6 deletions src/State/Gateway/GatewayStateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@
use ApiPlatform\Metadata as API;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProviderInterface;
use App\ApiResource\Gateway\Gateway;
use App\ApiResource\Gateway\GatewayApiResource;
use App\Gateway\GatewayInterface;
use App\Gateway\GatewayLocator;
use App\Mapping\Gateway\GatewayMapper;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;

class GatewayStateProvider implements ProviderInterface
{
public function __construct(
private GatewayLocator $gateways,
private GatewayMapper $gatewayMapper,
) {}

public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
Expand All @@ -31,20 +30,29 @@ private function getGateways(): array
{
$gateways = [];
foreach ($this->gateways->getAll() as $gateway) {
$gateways[] = $this->gatewayMapper->toResource($gateway);
$gateways[] = $this->toResource($gateway);
}

return $gateways;
}

private function getGateway(string $name): Gateway
private function getGateway(string $name): GatewayApiResource
{
try {
$gateway = $this->gateways->get($name);

return $this->gatewayMapper->toResource($gateway);
return $this->toResource($gateway);
} catch (\Exception $e) {
throw new NotFoundHttpException('Not Found');
}
}

private function toResource(GatewayInterface $gateway): GatewayApiResource
{
$resource = new GatewayApiResource();
$resource->name = $gateway::getName();
$resource->supports = $gateway::getSupportedChargeTypes();

return $resource;
}
}

0 comments on commit 88ca27c

Please sign in to comment.