diff --git a/src/ApiResource/Project/RewardApiResource.php b/src/ApiResource/Project/RewardApiResource.php index bf34027..8d33dbb 100644 --- a/src/ApiResource/Project/RewardApiResource.php +++ b/src/ApiResource/Project/RewardApiResource.php @@ -6,8 +6,8 @@ use ApiPlatform\Metadata as API; use App\Entity\Money; use App\Entity\Project\Reward; -use App\State\ApiResourceStateProcessor; use App\State\ApiResourceStateProvider; +use App\State\Project\RewardStateProcessor; use AutoMapper\Attribute\MapTo; use Symfony\Component\Validator\Constraints as Assert; @@ -18,7 +18,7 @@ shortName: 'ProjectReward', stateOptions: new Options(entityClass: Reward::class), provider: ApiResourceStateProvider::class, - processor: ApiResourceStateProcessor::class + processor: RewardStateProcessor::class )] class RewardApiResource { diff --git a/src/State/Project/ProjectStateProcessor.php b/src/State/Project/ProjectStateProcessor.php index 29784db..673686c 100644 --- a/src/State/Project/ProjectStateProcessor.php +++ b/src/State/Project/ProjectStateProcessor.php @@ -29,7 +29,7 @@ public function process(mixed $data, Operation $operation, array $uriVariables = /** @var Project */ $project = $this->autoMapper->map($data, Project::class); - if (!isset($data->id)) { + if (!$project->getId()) { $owner = $this->authService->getUser(); if (!$owner) { diff --git a/src/State/Project/RewardStateProcessor.php b/src/State/Project/RewardStateProcessor.php new file mode 100644 index 0000000..6168a15 --- /dev/null +++ b/src/State/Project/RewardStateProcessor.php @@ -0,0 +1,37 @@ +autoMapper->map($data, Reward::class); + + if (!$reward->getId()) { + $reward->setUnitsAvailable($reward->getUnitsTotal()); + } + + $reward = $this->entityStateProcessor->process($reward, $operation, $uriVariables, $context); + + return $this->autoMapper->map($reward, $data); + } +}