Skip to content

Commit

Permalink
Uml 3459 return sirius data via new endpoint in new format (#2770)
Browse files Browse the repository at this point in the history
* UML-3460 Return LPA store LPAs via the new endpoint in the new format

* UML-3460 serialised objects, transforming enum and datetimes. used inheritance for the entities to help structure datastore and for future sirius implementation

* UML-3460 added tests for casters

* UML-3460 using datetime immutable instead of interface

* UML-3460 using datetime  interface in DateToStringSerializer.php

* UML-3460 removed unnecessary lpastore person
created new files for dedicated tests

* UML-3459 updated properties to alphabetical order

* UML-3459 added mappings of linked ids

* Update service-api/app/test/AppTest/Entity/CanSerialiseSiriusToModerniseFormatTest.php

Co-authored-by: Adam Cooper <[email protected]>

* UML 3459 updated can_cast_sirius_donor test to also test linked donors

---------

Co-authored-by: Adam Cooper <[email protected]>
  • Loading branch information
allenannom and cooperaj authored Sep 23, 2024
1 parent aaa4641 commit a4273b6
Show file tree
Hide file tree
Showing 29 changed files with 1,433 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use App\Entity\Sirius\SiriusLpaDonor;
use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;
use EventSauce\ObjectHydrator\UnableToHydrateObject;

#[Attribute(Attribute::TARGET_PARAMETER)]
class CastSiriusDonor implements PropertyCaster
{
/**
* @throws UnableToHydrateObject
*/
public function cast(mixed $value, ObjectMapper $hydrator): mixed
{
return $hydrator->hydrateObject(SiriusLpaDonor::class, $value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use App\Enum\LifeSustainingTreatment;
use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class CastToSiriusLifeSustainingTreatment implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): mixed
{
return LifeSustainingTreatment::fromShortName($value)->value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractAddressLine1FromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['addressLine1'])) {
return $value[0]['addressLine1'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractAddressLine2FromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['addressLine2'])) {
return $value[0]['addressLine2'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractAddressLine3FromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['addressLine3'])) {
return $value[0]['addressLine3'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractCountryFromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['country'])) {
return $value[0]['country'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractCountyFromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['county'])) {
return $value[0]['county'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractPostcodeFromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['postcode'])) {
return $value[0]['postcode'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractTownFromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['town'])) {
return $value[0]['town'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;

#[Attribute(Attribute::TARGET_PARAMETER)]
class ExtractTypeFromSiriusLpa implements PropertyCaster
{
public function cast(mixed $value, ObjectMapper $hydrator): ?string
{
if (is_array($value) && isset($value[0]['type'])) {
return $value[0]['type'];
}

return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius\Casters;

use Attribute;
use EventSauce\ObjectHydrator\ObjectMapper;
use EventSauce\ObjectHydrator\PropertyCaster;
use EventSauce\ObjectHydrator\UnableToHydrateObject;

#[Attribute(Attribute::TARGET_PARAMETER)]
class LinkedDonorCaster implements PropertyCaster
{
/**
* @throws UnableToHydrateObject
*/
public function cast(mixed $value, ObjectMapper $hydrator): array
{
$linkedDonors = [];

foreach ($value as $linked) {
$linkedDonors[] = [
'id' => $linked['id'],
'uId' => $linked['uId'],
];
}

return $linkedDonors;
}
}
78 changes: 78 additions & 0 deletions service-api/app/src/App/src/Entity/Sirius/SiriusLpa.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

declare(strict_types=1);

namespace App\Entity\Sirius;

use App\Entity\Casters\CastToWhenTheLpaCanBeUsed;
use App\Entity\Lpa;
use App\Enum\HowAttorneysMakeDecisions;
use App\Enum\LifeSustainingTreatment;
use App\Enum\LpaType;
use DateTimeImmutable;
use EventSauce\ObjectHydrator\PropertyCasters\CastListToType;
use App\Entity\Sirius\Casters\CastSiriusDonor;
use App\Entity\Sirius\Casters\CastToSiriusLifeSustainingTreatment;

class SiriusLpa extends Lpa
{
public function __construct(
?bool $applicationHasGuidance,
?bool $applicationHasRestrictions,
?string $applicationType,
#[CastToWhenTheLpaCanBeUsed]
?HowAttorneysMakeDecisions $attorneyActDecisions,
#[CastListToType(SiriusLpaAttorney::class)]
?array $attorneys,
?LpaType $caseSubtype,
?string $channel,
?DateTimeImmutable $dispatchDate,
#[CastSiriusDonor]
?object $donor,
?bool $hasSeveranceWarning,
?DateTimeImmutable $invalidDate,
#[CastToSiriusLifeSustainingTreatment]
?LifeSustainingTreatment $lifeSustainingTreatment,
?DateTimeImmutable $lpaDonorSignatureDate,
?bool $lpaIsCleansed,
?string $onlineLpaId,
?DateTimeImmutable $receiptDate,
?DateTimeImmutable $registrationDate,
?DateTimeImmutable $rejectedDate,
#[CastListToType(SiriusLpaAttorney::class)]
?array $replacementAttorneys,
?string $status,
?DateTimeImmutable $statusDate,
#[CastListToType(SiriusLpaTrustCorporations::class)]
?array $trustCorporations,
?string $uId,
?DateTimeImmutable $withdrawnDate,
) {
parent::__construct(
$applicationHasGuidance,
$applicationHasRestrictions,
$applicationType,
$attorneyActDecisions,
$attorneys,
$caseSubtype,
$channel,
$dispatchDate,
$donor,
$hasSeveranceWarning,
$invalidDate,
$lifeSustainingTreatment,
$lpaDonorSignatureDate,
$lpaIsCleansed,
$onlineLpaId,
$receiptDate,
$registrationDate,
$rejectedDate,
$replacementAttorneys,
$status,
$statusDate,
$trustCorporations,
$uId,
$withdrawnDate
);
}
}
Loading

0 comments on commit a4273b6

Please sign in to comment.