-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from GoteoFoundation/feat/project-rewards
[feat] Project Rewards
- Loading branch information
Showing
16 changed files
with
527 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace App\ApiResource\Project; | ||
|
||
use ApiPlatform\Doctrine\Orm\State\Options; | ||
use ApiPlatform\Metadata as API; | ||
use App\Entity\Money; | ||
use App\Entity\Project\Reward; | ||
use App\State\ApiResourceStateProcessor; | ||
use App\State\ApiResourceStateProvider; | ||
use AutoMapper\Attribute\MapTo; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* A ProjectReward is something the Project owner wishes to give in exchange for contributions to their Project. | ||
*/ | ||
#[API\ApiResource( | ||
shortName: 'ProjectReward', | ||
stateOptions: new Options(entityClass: Reward::class), | ||
provider: ApiResourceStateProvider::class, | ||
processor: ApiResourceStateProcessor::class | ||
)] | ||
class RewardApiResource | ||
{ | ||
#[API\ApiProperty(identifier: true, writable: false)] | ||
public int $id; | ||
|
||
/** | ||
* The project which gives this reward. | ||
*/ | ||
#[Assert\NotBlank()] | ||
public ProjectApiResource $project; | ||
|
||
/** | ||
* A short, descriptive title for this reward. | ||
*/ | ||
#[Assert\NotBlank()] | ||
public string $title; | ||
|
||
/** | ||
* Detailed information about this reward. | ||
*/ | ||
#[MapTo(if: 'source.description != null')] | ||
public ?string $description = null; | ||
|
||
/** | ||
* The minimal monetary sum to be able to claim this reward. | ||
*/ | ||
#[Assert\NotBlank()] | ||
public Money $money; | ||
|
||
/** | ||
* Rewards might be finite, i.e: has a limited amount of existing unitsTotal. | ||
*/ | ||
#[Assert\NotNull()] | ||
#[Assert\Type('bool')] | ||
public bool $hasUnits; | ||
|
||
/** | ||
* For finite rewards, the total amount of existing unitsTotal. | ||
*/ | ||
#[Assert\When( | ||
'this.hasUnits == true', | ||
constraints: [new Assert\Positive()] | ||
)] | ||
public int $unitsTotal = 0; | ||
|
||
/** | ||
* For finite rewards, the currently available amount of unitsTotal that can be claimed. | ||
*/ | ||
#[API\ApiProperty(writable: false)] | ||
public int $unitsAvailable = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace App\ApiResource\Project; | ||
|
||
use ApiPlatform\Doctrine\Orm\State\Options; | ||
use ApiPlatform\Metadata as API; | ||
use App\ApiResource\User\UserApiResource; | ||
use App\Entity\Project\RewardClaim; | ||
use App\State\ApiResourceStateProcessor; | ||
use App\State\ApiResourceStateProvider; | ||
use Symfony\Component\Validator\Constraints as Assert; | ||
|
||
/** | ||
* A ProjectRewardClaim represents the will of an User who wishes to obtain one ProjectReward. | ||
*/ | ||
#[API\ApiResource( | ||
shortName: 'ProjectRewardClaim', | ||
stateOptions: new Options(entityClass: RewardClaim::class), | ||
provider: ApiResourceStateProvider::class, | ||
processor: ApiResourceStateProcessor::class | ||
)] | ||
class RewardClaimApiResource | ||
{ | ||
#[API\ApiProperty(identifier: true, writable: false)] | ||
public int $id; | ||
|
||
/** | ||
* The ProjectReward being claimed. | ||
*/ | ||
#[Assert\NotBlank()] | ||
public RewardApiResource $reward; | ||
|
||
/** | ||
* The User claiming the ProjectReward. | ||
*/ | ||
#[API\ApiProperty(writable: false)] | ||
public UserApiResource $owner; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.