refactor: use new repository, update logic
This commit is contained in:
parent
24151c26ec
commit
14fe0f6ddb
|
@ -4,45 +4,26 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace App\Command;
|
namespace App\Command;
|
||||||
|
|
||||||
use App\Collection\RsvpCollection;
|
use App\EventRepository;
|
||||||
use App\UseCase\FindTheWinner;
|
|
||||||
use App\ValueObject\Winner;
|
|
||||||
use DateInterval;
|
|
||||||
use Illuminate\Support\Collection;
|
|
||||||
use Symfony\Component\Console\Command\Command;
|
use Symfony\Component\Console\Command\Command;
|
||||||
use Symfony\Component\Console\Input\InputArgument;
|
use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
use Symfony\Component\Console\Style\SymfonyStyle;
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
use Symfony\Contracts\Cache\CacheInterface;
|
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
|
||||||
|
|
||||||
final class GetRaffleWinnerCommand extends Command
|
final class GetRaffleWinnerCommand extends Command
|
||||||
{
|
{
|
||||||
|
|
||||||
protected static $defaultName = 'meetup:pick-winner';
|
protected static $defaultName = 'meetup:pick-winner';
|
||||||
|
|
||||||
private HttpClientInterface $client;
|
private EventRepository $eventRepository;
|
||||||
|
|
||||||
private CacheInterface $cache;
|
|
||||||
|
|
||||||
private array $eventData = [];
|
|
||||||
|
|
||||||
private Collection $rsvps;
|
|
||||||
|
|
||||||
private Collection $yesRsvps;
|
|
||||||
|
|
||||||
private ?array $winner;
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
HttpClientInterface $client,
|
EventRepository $eventRepository,
|
||||||
CacheInterface $cache,
|
|
||||||
string $name = null
|
string $name = null
|
||||||
) {
|
) {
|
||||||
parent::__construct($name);
|
parent::__construct($name);
|
||||||
|
|
||||||
$this->client = $client;
|
$this->eventRepository = $eventRepository;
|
||||||
$this->cache = $cache;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function configure()
|
protected function configure()
|
||||||
|
@ -63,38 +44,20 @@ final class GetRaffleWinnerCommand extends Command
|
||||||
$io = new SymfonyStyle($input, $output);
|
$io = new SymfonyStyle($input, $output);
|
||||||
$eventId = (int)$input->getArgument('event_id');
|
$eventId = (int)$input->getArgument('event_id');
|
||||||
|
|
||||||
$result = (new FindTheWinner(
|
$attendees = $this->eventRepository->findAttendeesForEvent($eventId);
|
||||||
$this->client,
|
|
||||||
$this->cache,
|
|
||||||
$eventId
|
|
||||||
))->__invoke();
|
|
||||||
|
|
||||||
$event = $result->getEvent();
|
$winner = $attendees->random();
|
||||||
$io->title($event->getName());
|
|
||||||
$io->text($event->getLink());
|
|
||||||
|
|
||||||
$io->section(
|
$io->title('Meetup Raffle Winner Picker');
|
||||||
sprintf(
|
|
||||||
'%s \'yes\' RSVPs (excluding hosts)',
|
|
||||||
$result->getRsvps()->count()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
$io->listing($result->getRsvps()->getNames()->toArray());
|
$io->text(sprintf('"Yes" RSVPs (%d):', $attendees->count()));
|
||||||
|
$io->newLine();
|
||||||
|
|
||||||
$io->writeln(
|
// TODO: this is meetup specific, so needs to be made agnostic.
|
||||||
sprintf('Winner: %s', $result->getWinner()->getName())
|
$io->listing($attendees->map->member->map->name->toArray());
|
||||||
);
|
|
||||||
|
|
||||||
$this->openWinnerPhoto($result->getWinner(), $io);
|
$io->success($winner->member->name);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function openWinnerPhoto(Winner $winner, SymfonyStyle $io): void
|
|
||||||
{
|
|
||||||
if ($photo = $winner->getPhoto()) {
|
|
||||||
$io->write($photo);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue