chg: usr: re-implement the waiting for opponent dialog - refactor its gfx - & add online user selection dialog #4
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Entity\PlayedGame;
|
||||
use App\Repository\PlayedGameRepository;
|
||||
use App\Util\RpcManager;
|
||||
use App\Util\TopicManager;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
@@ -81,6 +83,29 @@ class MercureController extends AbstractController
|
||||
return $this->json(['success' => true]);
|
||||
}
|
||||
|
||||
#[Route('/api/game/waiting', name: 'MineSeekerBundle_api_game_waiting', methods: ['GET'])]
|
||||
public function waiting(PlayedGameRepository $repo): JsonResponse
|
||||
{
|
||||
$games = $repo->findWaitingGames();
|
||||
|
||||
$result = array_map(static function (PlayedGame $g): array {
|
||||
$name = match (true) {
|
||||
null !== $g->getRed() => $g->getRed()->getUsername(),
|
||||
null !== $g->getRedAnon() => $g->getRedAnon()->getUserName(),
|
||||
null !== $g->getBlue() => $g->getBlue()->getUsername(),
|
||||
default => $g->getBlueAnon()?->getUserName() ?? 'Unknown',
|
||||
};
|
||||
|
||||
return [
|
||||
'gameAssoc' => $g->getGameAssoc(),
|
||||
'name' => $name,
|
||||
'since' => $g->getCreated()?->format(\DateTimeInterface::ATOM) ?? '',
|
||||
];
|
||||
}, $games);
|
||||
|
||||
return $this->json($result);
|
||||
}
|
||||
|
||||
private function resolveUserName(Request $request): string
|
||||
{
|
||||
$user = $this->getUser();
|
||||
|
||||
Reference in New Issue
Block a user