Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Infrastructure\Persistence\Doctrine\Report;
namespace App\Infrastructure\Persistence\Doctrine\Report\Repository;

use App\Domain\Model\Report\ReportComment;
use App\Domain\Repository\Report\ReportCommentRepositoryInterface;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace App\Infrastructure\Persistence\Doctrine\Report;
namespace App\Infrastructure\Persistence\Doctrine\Report\Repository;

use App\Domain\Model\Report\Report;
use App\Domain\Repository\Report\ReportRepositoryInterface;
Expand Down
64 changes: 35 additions & 29 deletions src/Presentation/Controller/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@
#[Route(path: '/reports')]
class ReportsController extends AbstractController
{
#[Route(path: '/{gameSlug}', name: 'reports_for_game', methods: [Request::METHOD_GET])]
#[
Route(
path: '/{gameSlug}',
name: 'reports_for_game',
methods: [Request::METHOD_GET],
),
]
public function reportsForGame(
string $gameSlug,
MessageBusInterface $messageBus,
MessageBusHelper $messageBusHelper,
): Response {
$gameEnvelope = $messageBus->dispatch(new GetGameBySlugQuery($gameSlug));
$gameEnvelope = $messageBus->dispatch(
new GetGameBySlugQuery($gameSlug),
);

/** @var ?Game $game */
$game = $messageBusHelper->getContentFromEnvelope(
Expand All @@ -38,9 +46,13 @@ class: Game::class,

if (null === $game) {
try {
$messageBus->dispatch(new CreateGameWithCacheCheckCommand($gameSlug));
$messageBus->dispatch(
new CreateGameWithCacheCheckCommand($gameSlug),
);

$gameEnvelope = $messageBus->dispatch(new GetGameBySlugQuery($gameSlug));
$gameEnvelope = $messageBus->dispatch(
new GetGameBySlugQuery($gameSlug),
);

/** @var ?Game $game */
$game = $messageBusHelper->getContentFromEnvelope(
Expand All @@ -53,21 +65,19 @@ class: Game::class,
'@app/reports/reports_for_game.html.twig',
[
'error' => $e->getMessage(),
]
],
);
}
}

if (null === $game) {
return $this->render(
'@app/reports/reports_for_game.html.twig',
[
'error' => 'Game retrieval failed',
]
);
return $this->render('@app/reports/reports_for_game.html.twig', [
'error' => 'Game retrieval failed',
]);
}

$reports = $game->getReports()->toArray();
$mostUpvotedReport = null;

if (!empty($reports)) {
/** @var array<int, Report> $reports */
Expand All @@ -78,31 +88,27 @@ class: Game::class,

return $b->getCreatedAt() <=> $a->getCreatedAt();
});

$mostUpvotedReport = $reports[0];
}

$createReportForm = $this->createForm(
CreateReportForm::class,
null,
[
'action' => $this->generateUrl('create_report'),
'method' => Request::METHOD_POST,
]
);
$createReportForm = $this->createForm(CreateReportForm::class, null, [
'action' => $this->generateUrl('create_report'),
'method' => Request::METHOD_POST,
]);

$createReportCommentForm = $this->createForm(
CreateReportCommentForm::class,
null,
);

return $this->render(
'@app/reports/reports_for_game.html.twig',
[
'game' => $game,
'reports' => $reports ?? [],
'gameSlug' => $game->getSlug(),
'createReportForm' => $createReportForm->createView(),
'createReportCommentForm' => $createReportCommentForm->createView(),
]
);
return $this->render('@app/reports/reports_for_game.html.twig', [
'game' => $game,
'reports' => $reports ?? [],
'gameSlug' => $game->getSlug(),
'mostUpvotedReport' => $mostUpvotedReport,
'createReportForm' => $createReportForm->createView(),
'createReportCommentForm' => $createReportCommentForm->createView(),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use App\Application\Query\Report\GetReportByIdQuery;
use App\Domain\Model\Report\Report;
use App\Domain\Model\Report\ReportComment;
use App\Infrastructure\Persistence\Doctrine\Report\DoctrineReportCommentRepository;
use App\Infrastructure\Persistence\Doctrine\Report\Repository\DoctrineReportCommentRepository;
use Faker\Factory;
use Psr\Log\LoggerInterface;
use Symfony\Component\Messenger\Envelope;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use App\Domain\Model\Report\Report;
use App\Infrastructure\Enum\ReportGameStatusEnum;
use App\Infrastructure\Persistence\Doctrine\Game\Repository\DoctrineGameRepository;
use App\Infrastructure\Persistence\Doctrine\Report\DoctrineReportRepository;
use App\Infrastructure\Persistence\Doctrine\Report\Repository\DoctrineReportRepository;
use App\Presentation\Dto\CreateReportFormInputDto;
use Faker\Factory;

Expand Down