diff --git a/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php b/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php index fdaa37ca95..a5f97675bc 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php +++ b/service-api/app/src/App/src/DataAccess/Repository/Response/Lpa.php @@ -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; } diff --git a/service-api/app/src/App/src/DataAccess/Repository/Response/LpaInterface.php b/service-api/app/src/App/src/DataAccess/Repository/Response/LpaInterface.php index 4c4ceeddce..f50679aa53 100644 --- a/service-api/app/src/App/src/DataAccess/Repository/Response/LpaInterface.php +++ b/service-api/app/src/App/src/DataAccess/Repository/Response/LpaInterface.php @@ -4,6 +4,7 @@ namespace App\DataAccess\Repository\Response; +use App\Entity\Lpa as CombinedFormatLpa; use App\Service\Lpa\SiriusLpa; use DateTimeInterface; @@ -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. diff --git a/service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php b/service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php index 9d0cf28d52..7428ad137d 100644 --- a/service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php +++ b/service-api/app/src/App/src/Service/Lpa/CombinedLpaManager.php @@ -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; /** @@ -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, ) { } public function getByUid(string $uid): ?LpaInterface { - return $this->siriusLpaManager->getByUid($uid); + throw new ApiException('Not implemented'); } public function getByUserLpaActorToken(string $token, string $userId): ?array { - return $this->siriusLpaManager->getByUserLpaActorToken($token, $userId); + throw new ApiException('Not implemented'); } - public function getAllForUser(string $userId): array + public function getAllActiveForUser(string $userId): array { // Returns an array of all the LPAs Ids (plus other metadata) in the user's account. $lpaActorMaps = $this->userLpaActorMapRepository->getByUserId($userId); @@ -46,7 +48,7 @@ public function getAllForUser(string $userId): array return $this->lookupAndFormatLpas($lpaActorMaps); } - public function getAllLpasAndRequestsForUser(string $userId): array + public function getAllForUser(string $userId): array { // Returns an array of all the LPAs Ids (plus other metadata) in the user's account. $lpaActorMaps = $this->userLpaActorMapRepository->getByUserId($userId); @@ -56,7 +58,7 @@ public function getAllLpasAndRequestsForUser(string $userId): array public function getByViewerCode(string $viewerCode, string $donorSurname, ?string $organisation = null): ?array { - return $this->siriusLpaManager->getByViewerCode($viewerCode, $donorSurname, $organisation); + throw new ApiException('Not implemented'); } /** @@ -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; }); // unusual combination operation in order to preserve potential numeric keys - $lpas = $siriusLpas + $dataStoreLpas; + $lpas = $keyedDataStoreLpas + $siriusLpas; $result = []; @@ -103,9 +105,7 @@ private function lookupAndFormatLpas(array $lpaActorMaps): array $lpaData = $lpa->getData(); - // 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']); //Extract and return only LPA's where status is Registered or Cancelled if (($this->isValidLpa)($lpaData)) { diff --git a/service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php b/service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php new file mode 100644 index 0000000000..8948189911 --- /dev/null +++ b/service-api/app/src/App/src/Service/Lpa/ResolveActor/LpaStoreHasActorTrait.php @@ -0,0 +1,73 @@ +isAPrimaryAttorney($uid); + + // If not an attorney or tc, check if they're the donor. + if ($actor === null) { + $actor = $this->isADonor($uid); + } + + // Is the actor a trust corporation + if ($actor === null) { + $actor = $this->isATrustCorporation($uid); + } + + return $actor; + } + + private function isAPrimaryAttorney(string $uid): ?LpaActor + { + foreach ($this->attorneys as $attorney) { + if ((string) $attorney->uId === $uid) { + return new LpaActor($attorney, ActorType::ATTORNEY); + } + } + + return null; + } + + private function isADonor(string $uid): ?LpaActor + { + if ($this->donor->uId === $uid) { + return new LpaActor($this->donor, ActorType::DONOR); + } + + return null; + } + + private function isATrustCorporation(string $uid): ?LpaActor + { + foreach ($this->trustCorporations as $tc) { + if ($tc->uId === $uid) { + return new LpaActor($tc, ActorType::TRUST_CORPORATION); + } + } + + return null; + } +}