Update RewardClaim creation process
This commit is contained in:
@@ -6,11 +6,11 @@ use ApiPlatform\Doctrine\Orm\State\Options;
|
||||
use ApiPlatform\Metadata as API;
|
||||
use App\ApiResource\Gateway\ChargeApiResource;
|
||||
use App\ApiResource\User\UserApiResource;
|
||||
use App\Dto\RewardClaimCreationDto;
|
||||
use App\Entity\Project\RewardClaim;
|
||||
use App\State\ApiResourceStateProvider;
|
||||
use App\State\Project\RewardClaimStateProcessor;
|
||||
use App\Validator\AvailableRewardUnits;
|
||||
use App\Validator\EnoughRewardCharge;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,10 @@ use Symfony\Component\Validator\Constraints as Assert;
|
||||
provider: ApiResourceStateProvider::class,
|
||||
processor: RewardClaimStateProcessor::class
|
||||
)]
|
||||
#[EnoughRewardCharge()]
|
||||
#[API\GetCollection()]
|
||||
#[API\Post(input: RewardClaimCreationDto::class)]
|
||||
#[API\Get()]
|
||||
#[API\Delete()]
|
||||
class RewardClaimApiResource
|
||||
{
|
||||
#[API\ApiProperty(identifier: true, writable: false)]
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Dto;
|
||||
|
||||
use App\ApiResource\Gateway\ChargeApiResource;
|
||||
use App\ApiResource\Project\RewardApiResource;
|
||||
use App\Validator\AvailableRewardUnits;
|
||||
use App\Validator\EnoughRewardCharge;
|
||||
use App\Validator\SameProjectRewardCharge;
|
||||
use App\Validator\SingleRewardClaimPerCharge;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
#[EnoughRewardCharge()]
|
||||
#[SameProjectRewardCharge()]
|
||||
#[SingleRewardClaimPerCharge()]
|
||||
class RewardClaimCreationDto
|
||||
{
|
||||
/**
|
||||
* The GatewayCharge granting access to the ProjectReward.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
public ChargeApiResource $charge;
|
||||
|
||||
/**
|
||||
* The ProjectReward being claimed.
|
||||
*/
|
||||
#[Assert\NotBlank()]
|
||||
#[AvailableRewardUnits()]
|
||||
public RewardApiResource $reward;
|
||||
}
|
||||
@@ -5,6 +5,7 @@ namespace App\State\Project;
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProcessorInterface;
|
||||
use App\ApiResource\Project\RewardClaimApiResource;
|
||||
use App\Dto\RewardClaimCreationDto;
|
||||
use App\Entity\Project\RewardClaim;
|
||||
use App\Mapping\AutoMapper;
|
||||
use App\Service\Auth\AuthService;
|
||||
@@ -20,7 +21,7 @@ class RewardClaimStateProcessor implements ProcessorInterface
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @param RewardClaimApiResource $data
|
||||
* @param RewardClaimApiResource|RewardClaimCreationDto $data
|
||||
*
|
||||
* @return RewardClaimApiResource|null
|
||||
*/
|
||||
@@ -29,7 +30,7 @@ class RewardClaimStateProcessor implements ProcessorInterface
|
||||
/** @var RewardClaim */
|
||||
$claim = $this->autoMapper->map($data, RewardClaim::class);
|
||||
|
||||
if (!$claim->getId()) {
|
||||
if ($data instanceof RewardClaimCreationDto) {
|
||||
$owner = $this->authService->getUser();
|
||||
|
||||
if (!$owner) {
|
||||
|
||||
Reference in New Issue
Block a user