chg: dev: refactor the code - there was unnecessary codes and wrongly formatted or designed code that are related to Repositories #7
This commit is contained in:
@@ -15,6 +15,8 @@ use App\Repository\PlayedGameRepository;
|
||||
use App\Service\ResolveUserNamesService;
|
||||
use App\Util\RpcManager;
|
||||
use App\Util\TopicManager;
|
||||
use DateTimeInterface;
|
||||
use Exception;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
@@ -49,10 +51,17 @@ class MercureController extends AbstractController
|
||||
#[Route('/api/game/start', name: 'MineSeekerBundle_api_game_start', methods: ['POST'])]
|
||||
public function start(Request $request): JsonResponse
|
||||
{
|
||||
$data = $request->toArray();
|
||||
$result = $this->rpcManager->saveGrid($data['gameAssoc']);
|
||||
try {
|
||||
$data = $request->toArray();
|
||||
$result = $this->rpcManager->saveGrid($data['gameAssoc']);
|
||||
|
||||
return $this->json(['success' => $result]);
|
||||
return $this->json(['success' => $result]);
|
||||
} catch (Exception $e) {
|
||||
return $this->json(
|
||||
['success' => false, 'error' => 'Failed to start game: ' . $e->getMessage()],
|
||||
Response::HTTP_INTERNAL_SERVER_ERROR
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[Route('/api/game/connect/{gameAssoc}', name: 'MineSeekerBundle_api_game_connect', methods: ['GET'])]
|
||||
@@ -61,7 +70,7 @@ class MercureController extends AbstractController
|
||||
try {
|
||||
$payload = $this->rpcManager->getConnectInformation($gameAssoc);
|
||||
return new Response($payload, Response::HTTP_OK, ['Content-Type' => 'text/plain']);
|
||||
} catch (\Exception $e) {
|
||||
} catch (Exception $e) {
|
||||
return new Response('', Response::HTTP_INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -146,7 +155,7 @@ class MercureController extends AbstractController
|
||||
return [
|
||||
'gameAssoc' => $g->gameAssoc,
|
||||
'name' => $name,
|
||||
'since' => $g->created?->format(\DateTimeInterface::ATOM) ?? '',
|
||||
'since' => $g->created?->format(DateTimeInterface::ATOM) ?? '',
|
||||
];
|
||||
}, $games);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user