Skip to content

Commit

Permalink
Work to further combine lpa types
Browse files Browse the repository at this point in the history
  • Loading branch information
cooperaj committed Nov 19, 2024
1 parent b5cc270 commit 160dd89
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,24 @@

namespace App\DataAccess\Repository\Response;

use App\Entity\Lpa as CombinedFormatLpa;
use App\Service\Lpa\SiriusLpa;
use DateTimeInterface;

final class Lpa implements LpaInterface
{
/**
* @param array|SiriusLpa|null $data Array or object representing the LPA's data.
* @param DateTimeInterface|null $lookupTime The datetime that the data was looked up in Sirius main database.
* @param array|SiriusLpa|CombinedFormatLpa|null $data Array or object representing the LPA's data.
* @param DateTimeInterface|null $lookupTime The datetime that the data was looked up in
* Sirius main database.
*/
public function __construct(
private array|SiriusLpa|null $data,
private array|SiriusLpa|CombinedFormatLpa|null $data,
private ?DateTimeInterface $lookupTime,
) {
}

public function getData(): array|SiriusLpa|null
public function getData(): array|SiriusLpa|CombinedFormatLpa|null
{
return $this->data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace App\DataAccess\Repository\Response;

use App\Entity\Lpa as CombinedFormatLpa;
use App\Service\Lpa\SiriusLpa;
use DateTimeInterface;

Expand All @@ -12,7 +13,7 @@ interface LpaInterface
/**
* Returns the data the makes up the LPA.
*/
public function getData(): array|SiriusLpa|null;
public function getData(): array|SiriusLpa|CombinedFormatLpa|null;

/**
* Returns the Date & Time that the data was looked up in Sirius main database.
Expand Down
22 changes: 11 additions & 11 deletions service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\DataAccess\ApiGateway\SiriusLpas;
use App\DataAccess\Repository\Response\LpaInterface;
use App\DataAccess\Repository\UserLpaActorMapInterface;
use App\Exception\ApiException;
use App\Service\Lpa\Combined\ResolveLpaTypes;

/**
Expand All @@ -20,21 +21,22 @@ public function __construct(
private readonly ResolveLpaTypes $resolveLpaTypes,
private readonly SiriusLpas $siriusLpas,
private readonly DataStoreLpas $dataStoreLpas,
private readonly SiriusLpaManager $siriusLpaManager,
private ResolveActor $resolveActor,
private IsValidLpa $isValidLpa,
) {
}

Check warning on line 27 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L27

Added line #L27 was not covered by tests

public function getByUid(string $uid): ?LpaInterface

Check warning on line 29 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L29

Added line #L29 was not covered by tests
{
return $this->siriusLpaManager->getByUid($uid);
throw new ApiException('Not implemented');

Check warning on line 31 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L31

Added line #L31 was not covered by tests
}

public function getByUserLpaActorToken(string $token, string $userId): ?array

Check warning on line 34 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L34

Added line #L34 was not covered by tests
{
return $this->siriusLpaManager->getByUserLpaActorToken($token, $userId);
throw new ApiException('Not implemented');

Check warning on line 36 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L36

Added line #L36 was not covered by tests
}

public function getAllForUser(string $userId): array
public function getAllActiveForUser(string $userId): array

Check warning on line 39 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L39

Added line #L39 was not covered by tests
{
// Returns an array of all the LPAs Ids (plus other metadata) in the user's account.
$lpaActorMaps = $this->userLpaActorMapRepository->getByUserId($userId);

Check warning on line 42 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L42

Added line #L42 was not covered by tests
Expand All @@ -46,7 +48,7 @@ public function getAllForUser(string $userId): array
return $this->lookupAndFormatLpas($lpaActorMaps);

Check warning on line 48 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L48

Added line #L48 was not covered by tests
}

public function getAllLpasAndRequestsForUser(string $userId): array
public function getAllForUser(string $userId): array

Check warning on line 51 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L51

Added line #L51 was not covered by tests
{
// Returns an array of all the LPAs Ids (plus other metadata) in the user's account.
$lpaActorMaps = $this->userLpaActorMapRepository->getByUserId($userId);

Check warning on line 54 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L54

Added line #L54 was not covered by tests
Expand All @@ -56,7 +58,7 @@ public function getAllLpasAndRequestsForUser(string $userId): array

public function getByViewerCode(string $viewerCode, string $donorSurname, ?string $organisation = null): ?array

Check warning on line 59 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L59

Added line #L59 was not covered by tests
{
return $this->siriusLpaManager->getByViewerCode($viewerCode, $donorSurname, $organisation);
throw new ApiException('Not implemented');

Check warning on line 61 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L61

Added line #L61 was not covered by tests
}

/**
Expand All @@ -80,11 +82,11 @@ private function lookupAndFormatLpas(array $lpaActorMaps): array

$keyedDataStoreLpas = [];
array_walk($dataStoreLpas, function (LpaInterface $item) use (&$keyedDataStoreLpas) {
$keyedDataStoreLpas[$item->getData()['uid']] = $item;
$keyedDataStoreLpas[$item->getData()->uId] = $item;
});

Check warning on line 86 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L83-L86

Added lines #L83 - L86 were not covered by tests

// unusual combination operation in order to preserve potential numeric keys
$lpas = $siriusLpas + $dataStoreLpas;
$lpas = $keyedDataStoreLpas + $siriusLpas;

Check warning on line 89 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L89

Added line #L89 was not covered by tests

$result = [];

Check warning on line 91 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L91

Added line #L91 was not covered by tests

Expand All @@ -103,9 +105,7 @@ private function lookupAndFormatLpas(array $lpaActorMaps): array

$lpaData = $lpa->getData();

Check warning on line 106 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L106

Added line #L106 was not covered by tests

// TODO load lpaData into object hydrator
// TODO combined resolveActor that uses object
$actor = ($this->resolveActor)($lpaData, (int) $item['ActorId']);
$actor = ($this->resolveActor)($lpaData, (string) $item['ActorId']);

Check warning on line 108 in service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php#L108

Added line #L108 was not covered by tests

//Extract and return only LPA's where status is Registered or Cancelled
if (($this->isValidLpa)($lpaData)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

declare(strict_types=1);

namespace App\Service\Lpa\ResolveActor;

use App\Entity\LpaStore\LpaStoreAttorney;
use App\Entity\LpaStore\LpaStoreDonor;
use App\Entity\LpaStore\LpaStoreTrustCorporations;

/**
* @psalm-require-implements HasActorInterface
*/
trait LpaStoreHasActorTrait
{
/** @var LpaStoreAttorney[] */
public readonly ?array $attorneys;

/** @psalm-var ?LpaStoreDonor */
public readonly ?object $donor;

/** @var LpaStoreTrustCorporations[] */
public readonly ?array $trustCorporations;

public function hasActor(string $uid): ?LpaActor

Check warning on line 25 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L25

Added line #L25 was not covered by tests
{
// Determine if the actor is a primary attorney
$actor = $this->isAPrimaryAttorney($uid);

Check warning on line 28 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L28

Added line #L28 was not covered by tests

// If not an attorney or tc, check if they're the donor.
if ($actor === null) {
$actor = $this->isADonor($uid);

Check warning on line 32 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L31-L32

Added lines #L31 - L32 were not covered by tests
}

// Is the actor a trust corporation
if ($actor === null) {
$actor = $this->isATrustCorporation($uid);

Check warning on line 37 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L36-L37

Added lines #L36 - L37 were not covered by tests
}

return $actor;

Check warning on line 40 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L40

Added line #L40 was not covered by tests
}

private function isAPrimaryAttorney(string $uid): ?LpaActor

Check warning on line 43 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L43

Added line #L43 was not covered by tests
{
foreach ($this->attorneys as $attorney) {
if ((string) $attorney->uId === $uid) {
return new LpaActor($attorney, ActorType::ATTORNEY);

Check warning on line 47 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L45-L47

Added lines #L45 - L47 were not covered by tests
}
}

return null;

Check warning on line 51 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L51

Added line #L51 was not covered by tests
}

private function isADonor(string $uid): ?LpaActor

Check warning on line 54 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L54

Added line #L54 was not covered by tests
{
if ($this->donor->uId === $uid) {
return new LpaActor($this->donor, ActorType::DONOR);

Check warning on line 57 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L56-L57

Added lines #L56 - L57 were not covered by tests
}

return null;

Check warning on line 60 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L60

Added line #L60 was not covered by tests
}

private function isATrustCorporation(string $uid): ?LpaActor

Check warning on line 63 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L63

Added line #L63 was not covered by tests
{
foreach ($this->trustCorporations as $tc) {
if ($tc->uId === $uid) {
return new LpaActor($tc, ActorType::TRUST_CORPORATION);

Check warning on line 67 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L65-L67

Added lines #L65 - L67 were not covered by tests
}
}

return null;

Check warning on line 71 in service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php

View check run for this annotation

Codecov / codecov/patch

service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php#L71

Added line #L71 was not covered by tests
}
}

0 comments on commit 160dd89

Please sign in to comment.