-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add endpoint to see if user has reward
- Loading branch information
Showing
6 changed files
with
134 additions
and
25 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,50 @@ | ||
<?php | ||
|
||
namespace App\Entity; | ||
|
||
use App\Repository\InvestRewardRepository; | ||
use Doctrine\ORM\Mapping as ORM; | ||
|
||
#[ORM\Entity(repositoryClass: InvestRewardRepository::class)] | ||
class InvestReward | ||
{ | ||
#[ORM\Id] | ||
#[ORM\GeneratedValue] | ||
#[ORM\Column] | ||
private ?int $id = null; | ||
|
||
#[ORM\Column()] | ||
private ?int $invest = null; | ||
|
||
#[ORM\Column()] | ||
private ?int $reward = null; | ||
|
||
public function getId(): ?int | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function getInvest(): ?int | ||
{ | ||
return $this->invest; | ||
} | ||
|
||
public function setInvest(int $invest): static | ||
{ | ||
$this->invest = $invest; | ||
|
||
return $this; | ||
} | ||
|
||
public function getReward(): ?int | ||
{ | ||
return $this->reward; | ||
} | ||
|
||
public function setReward(int $reward): static | ||
{ | ||
$this->reward = $reward; | ||
|
||
return $this; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
namespace App\Repository; | ||
|
||
use App\Entity\InvestReward; | ||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; | ||
use Doctrine\Persistence\ManagerRegistry; | ||
|
||
/** | ||
* @extends ServiceEntityRepository<InvestReward> | ||
* | ||
* @method InvestReward|null find($id, $lockMode = null, $lockVersion = null) | ||
* @method InvestReward|null findOneBy(array $criteria, array $orderBy = null) | ||
* @method InvestReward[] findAll() | ||
* @method InvestReward[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) | ||
*/ | ||
class InvestRewardRepository extends ServiceEntityRepository | ||
{ | ||
public function __construct(ManagerRegistry $registry) | ||
{ | ||
parent::__construct($registry, InvestReward::class); | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
/* | ||
* This file is part of the Goteo Package. | ||
* | ||
* (c) Platoniq y Fundación Goteo <[email protected]> | ||
* | ||
* For the full copyright and license information, please view the README.md | ||
* and LICENSE files that was distributed with this source code. | ||
*/ | ||
|
||
namespace App\UseCase; | ||
|
||
use App\Repository\InvestRepository; | ||
use App\Repository\UserRepository; | ||
|
||
class GetUserInvestedToRewardUseCase | ||
{ | ||
private UserRepository $userRepository; | ||
private InvestRepository $investRepository; | ||
|
||
public function __construct( | ||
UserRepository $userRepository, | ||
InvestRepository $investRepository | ||
) { | ||
$this->userRepository = $userRepository; | ||
$this->investRepository = $investRepository; | ||
} | ||
|
||
public function execute( | ||
int $reward_id, | ||
string $userId, | ||
): bool { | ||
$user = $this->userRepository->findById($userId); | ||
|
||
return $this->investRepository->hasUserInvestedInReward($user, $reward_id); | ||
} | ||
} |