Created
June 23, 2019 03:24
-
-
Save shin1x1/a91fff3d757dd8c1eb7e677528a7dc92 to your computer and use it in GitHub Desktop.
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
<?php | |
namespace Acme\Infrastructure\Repository; | |
use Acme\Domain\Exception\NotFoundException; | |
use Acme\Domain\Model\PointEmail; | |
use Acme\Domain\Model\UserId; | |
use Acme\Domain\Repository\PointEmailRepository; | |
use Acme\Infrastructure\Eloquent\EloquentUser; | |
final class EloquentPointEmailRepository implements PointEmailRepository | |
{ | |
/** @var EloquentUser */ | |
private $eloquentUser; | |
/** | |
* @param EloquentUser $eloquentUser | |
*/ | |
public function __construct(EloquentUser $eloquentUser) | |
{ | |
$this->eloquentUser = $eloquentUser; | |
} | |
/** | |
* @param UserId $id | |
* @return PointEmail | |
* @throws NotFoundException | |
*/ | |
public function findByUserId(UserId $id): PointEmail | |
{ | |
$record = $this->eloquentUser->newQuery() | |
->join('user_points', 'user_points.user_id', '=', 'users.id') | |
->where('id', $id->asInt()) | |
->first(['email', 'point']); | |
if ($record === null) { | |
throw new NotFoundException('PointEmail not found:' . $id); | |
} | |
return new PointEmail( | |
$record->email, | |
$record->point | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment