From f2ab0d6441de8fb3a273c0ed4263e4dc4fc2b717 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Wed, 11 Dec 2024 11:36:48 +0100 Subject: [PATCH] Update accounting api resource ownership settings --- .../Accounting/AccountingApiResource.php | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/ApiResource/Accounting/AccountingApiResource.php b/src/ApiResource/Accounting/AccountingApiResource.php index dafa806..60ce99b 100644 --- a/src/ApiResource/Accounting/AccountingApiResource.php +++ b/src/ApiResource/Accounting/AccountingApiResource.php @@ -4,8 +4,13 @@ namespace App\ApiResource\Accounting; use ApiPlatform\Doctrine\Orm\State\Options; use ApiPlatform\Metadata as API; +use App\ApiResource\Project\ProjectApiResource; +use App\ApiResource\User\UserApiResource; use App\Entity\Accounting\Accounting; use App\Entity\Money; +use App\Entity\Project\Project; +use App\Entity\Tipjar; +use App\Entity\User\User; use App\State\Accounting\AccountingStateProcessor; use App\State\Accounting\AccountingStateProvider; @@ -36,10 +41,34 @@ class AccountingApiResource */ public string $currency; + #[API\ApiProperty(readable: false, writable: false)] + public string $ownerClass; + + #[API\ApiProperty(readable: false, writable: false)] + public ?UserApiResource $user = null; + + #[API\ApiProperty(readable: false, writable: false)] + public ?ProjectApiResource $project = null; + + #[API\ApiProperty(readable: false, writable: false)] + public ?Tipjar $tipjar = null; + /** - * The resource owning this Accounting.\. + * The resource owning this Accounting. + * + * @return UserApiResource|ProjectApiResource|Tipjar */ - public mixed $owner; + public function getOwner(): object + { + switch ($this->ownerClass) { + case User::class: + return $this->user; + case Project::class: + return $this->project; + case Tipjar::class: + return $this->tipjar; + } + } /** * The money currently held by the Accounting.