Skip to content

Instantly share code, notes, and snippets.

@shin1x1
Created June 23, 2019 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shin1x1/a91fff3d757dd8c1eb7e677528a7dc92 to your computer and use it in GitHub Desktop.
Save shin1x1/a91fff3d757dd8c1eb7e677528a7dc92 to your computer and use it in GitHub Desktop.
<?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