[AccompanyingPeriod] add location to serialization

This commit is contained in:
Julien Fastré 2021-07-27 21:25:38 +02:00 committed by Marc Ducobu
parent 8f9c8bc1a6
commit f188cc2d27
2 changed files with 83 additions and 0 deletions

View File

@ -948,4 +948,67 @@ class AccompanyingPeriod implements TrackCreationInterface, TrackUpdateInterface
return $this;
}
public function getAddressLocation(): ?Address
{
return $this->addressLocation;
}
/**
* @Groups({"write"})
*/
public function setAddressLocation(?Address $addressLocation = null): self
{
$this->addressLocation = $addressLocation;
return $this;
}
/**
* @Groups({"read"})
*/
public function getPersonLocation(): ?Person
{
return $this->personLocation;
}
/**
* @Groups({"write"})
*/
public function setPersonLocation(?Person $person = null): self
{
$this->personLocation = $person;
return $this;
}
/**
* Get the location, taking precedence into account
*
* @Groups({"read"})
*/
public function getLocation(\DateTimeImmutable $at = null): ?Address
{
if ($this->getPersonLocation() instanceof Person) {
return $this->getPersonLocation()->getCurrentHouseholdAddress($at);
}
return $this->getAddressLocation();
}
/**
* Get where the location is
*
* @Groups({"read"})
*/
public function getLocationStatus(): string
{
if ($this->getPersonLocation() instanceof Person) {
return 'person';
} elseif ($this->getAddressLocation() instanceof Address) {
return 'address';
} else {
return 'none';
}
}
}

View File

@ -416,6 +416,26 @@ paths:
This is my an initial comment.
Say hello to the new "parcours"!
Setting person with id 8405 as locator:
value:
type: accompanying_period
id: 0
personLocation:
type: person
id: 8405
Removing person location for both person and address:
value:
type: accompanying_period
id: 0
personLocation: null
addressLocation: null
Adding address with id 7960 as temporarily address:
value:
type: accompanying_period
id: 0
personLocation: null
addressLocation:
id: 7960
responses:
401:
description: "Unauthorized"