From f188cc2d27017f4238613f33c5e41503e37070f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Fastr=C3=A9?= Date: Tue, 27 Jul 2021 21:25:38 +0200 Subject: [PATCH] [AccompanyingPeriod] add location to serialization --- .../Entity/AccompanyingPeriod.php | 63 +++++++++++++++++++ .../ChillPersonBundle/chill.api.specs.yaml | 20 ++++++ 2 files changed, 83 insertions(+) diff --git a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php index 41835e237..dda129296 100644 --- a/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php +++ b/src/Bundle/ChillPersonBundle/Entity/AccompanyingPeriod.php @@ -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'; + } + } } diff --git a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml index 9fba308c5..71d5c119e 100644 --- a/src/Bundle/ChillPersonBundle/chill.api.specs.yaml +++ b/src/Bundle/ChillPersonBundle/chill.api.specs.yaml @@ -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"