Skip to content

Commit

Permalink
Use LpaDataFormatter for LpaStore lpas
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperaj committed Nov 19, 2024
1 parent abb764a commit b5cc270
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\DataAccess\ApiGateway;

use App\Exception\ApiException;
use App\Service\Lpa\LpaDataFormatter;
use App\DataAccess\Repository\{LpasInterface, Response, Response\LpaInterface};
use DateTimeImmutable;
use Exception;
Expand All @@ -21,6 +22,7 @@ public function __construct(
RequestFactoryInterface $requestFactory,
StreamFactoryInterface $streamFactory,
RequestSignerFactory $requestSignerFactory,
private LpaDataFormatter $lpaDataFormatter,
string $apiBaseUri,
string $traceId,
) {
Expand Down Expand Up @@ -67,9 +69,11 @@ public function get(string $uid): ?LpaInterface
return match ($response->getStatusCode()) {
StatusCodeInterface::STATUS_OK =>
new Response\Lpa(
json_decode(
$response->getBody()->getContents(),
true
($this->lpaDataFormatter)(
json_decode(
$response->getBody()->getContents(),
true,
),
),
new DateTimeImmutable($response->getHeaderLine('Date'))
),
Expand Down Expand Up @@ -97,7 +101,10 @@ public function lookup(array $uids): array
$url = sprintf('%s/lpas', $this->apiBaseUri);

// TODO this identifier needs to come from somewhere
$signer = ($this->requestSignerFactory)(SignatureType::DataStoreLpas, "UniqueUserIdentifier");
$signer = ($this->requestSignerFactory)(
SignatureType::DataStoreLpas,
'UniqueUserIdentifier'
);

$request = $this->requestFactory
->createRequest('POST', $url)
Expand All @@ -122,7 +129,7 @@ public function lookup(array $uids): array
StatusCodeInterface::STATUS_OK =>
array_map(
fn ($lpaData) => new Response\Lpa(
$lpaData,
($this->lpaDataFormatter)($lpaData),
new DateTimeImmutable($response->getHeaderLine('Date'))
),
json_decode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace App\DataAccess\ApiGateway;

use App\Service\Log\RequestTracing;
use App\Service\Lpa\LpaDataFormatter;
use Exception;
use Psr\Container\ContainerInterface;
use Psr\Http\Client\ClientInterface;
Expand All @@ -26,6 +27,7 @@ public function __invoke(ContainerInterface $container): DataStoreLpas
$container->get(RequestFactoryInterface::class),
$container->get(StreamFactoryInterface::class),
$container->get(RequestSignerFactory::class),
$container->get(LpaDataFormatter::class),
$config['lpa_data_store_api']['endpoint'],
$container->get(RequestTracing::TRACE_PARAMETER_NAME),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct()
* @throws UnableToHydrateObject
* @throws RuntimeException
*/
public function __invoke(array $lpa)
public function __invoke(array $lpa): Lpa
{
$lpaObject = $this->hydrateObject($lpa);

Expand Down

0 comments on commit b5cc270

Please sign in to comment.