diff --git a/migrations/Version20250603073633.php b/migrations/Version20250603073633.php new file mode 100644 index 0000000..1bcb584 --- /dev/null +++ b/migrations/Version20250603073633.php @@ -0,0 +1,50 @@ +addSql(<<<'SQL' + CREATE TABLE emoji (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, code VARCHAR(255) NOT NULL, force DOUBLE PRECISION NOT NULL, robustesse DOUBLE PRECISION NOT NULL, intelligence DOUBLE PRECISION NOT NULL, vitesse DOUBLE PRECISION NOT NULL, nb_combat_gagne INTEGER NOT NULL, rarete INTEGER NOT NULL) + SQL); + $this->addSql(<<<'SQL' + CREATE TABLE messenger_messages (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, body CLOB NOT NULL, headers CLOB NOT NULL, queue_name VARCHAR(190) NOT NULL, created_at DATETIME NOT NULL, available_at DATETIME NOT NULL, delivered_at DATETIME DEFAULT NULL) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_75EA56E0FB7336F0 ON messenger_messages (queue_name) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_75EA56E0E3BD61CE ON messenger_messages (available_at) + SQL); + $this->addSql(<<<'SQL' + CREATE INDEX IDX_75EA56E016BA31DB ON messenger_messages (delivered_at) + SQL); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql(<<<'SQL' + DROP TABLE emoji + SQL); + $this->addSql(<<<'SQL' + DROP TABLE messenger_messages + SQL); + } +} diff --git a/src/Controller/EmojiController.php b/src/Controller/EmojiController.php index c846229..d6e54c6 100644 --- a/src/Controller/EmojiController.php +++ b/src/Controller/EmojiController.php @@ -5,6 +5,9 @@ use App\Entity\Emoji; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; +use Doctrine\ORM\EntityManagerInterface; +use App\Repository\EmojiRepository; +use Symfony\Component\HttpFoundation\JsonResponse; class EmojiController extends AbstractController { @@ -21,19 +24,33 @@ class EmojiController extends AbstractController return new Emoji(); } - #[Route('/emoji/fight', name: 'fight_emoji')] - public function fightEmoji(Emoji $emoji1, Emoji $emoji2): Emoji { + #[Route('/emoji/fight/{idEmoji1}/{idEmoji2}', name: 'fight_emoji')] + public function fightEmoji(int $idEmoji1, int $idEmoji2, EntityManagerInterface $entityManager, EmojiRepository $emojiRepository): JsonResponse { + $emoji1 = $emojiRepository->find($idEmoji1); + $emoji2 = $emojiRepository->find($idEmoji2); + + if (!$emoji1 || !$emoji2) { + return new JsonResponse(['error' => 'Emoji not found'], 404); + } $aleatoire = random_int(0,3); $valEmoji1 = [$emoji1->getForce(),$emoji1->getRobustesse(),$emoji1->getIntelligence(),$emoji1->getVitesse()]; $valEmoji2 = [$emoji2->getForce(),$emoji2->getRobustesse(),$emoji2->getIntelligence(),$emoji2->getVitesse()]; $difference = $valEmoji1[$aleatoire] - $valEmoji2[$aleatoire]; if($difference > 0){ $emoji1->wonFight(); - return $emoji1; + $entityManager->persist($emoji1); + $entityManager->remove($emoji2); } else { $emoji2->wonFight(); - return $emoji2; + $entityManager->persist($emoji1); + $entityManager->remove($emoji2); } + + $entityManager->flush(); + + return new JsonResponse([ + 'message' => 'End of the fight', + ]); } public function testToMove(){