Compare commits
No commits in common. 'main' and 'Jade-Front' have entirely different histories.
main
...
Jade-Front
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250529204111 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__emoji AS SELECT id, nom, code, intelligence FROM emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE emoji (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, rarity_id INTEGER NOT NULL, name VARCHAR(255) NOT NULL, code VARCHAR(255) NOT NULL, intelligence DOUBLE PRECISION NOT NULL, strength DOUBLE PRECISION NOT NULL, toughness DOUBLE PRECISION NOT NULL, speed DOUBLE PRECISION NOT NULL, fights_won INTEGER NOT NULL, CONSTRAINT FK_B64BF632F3747573 FOREIGN KEY (rarity_id) REFERENCES rarity (id) NOT DEFERRABLE INITIALLY IMMEDIATE)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO emoji (id, name, code, intelligence) SELECT id, nom, code, intelligence FROM __temp__emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE __temp__emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_B64BF632F3747573 ON emoji (rarity_id)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__emoji AS SELECT id, name, code, intelligence FROM emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE emoji (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, nom VARCHAR(255) NOT NULL, code VARCHAR(255) NOT NULL, intelligence DOUBLE PRECISION NOT NULL, force DOUBLE PRECISION NOT NULL, robustesse DOUBLE PRECISION NOT NULL, vitesse DOUBLE PRECISION NOT NULL, nb_combat_gagne INTEGER NOT NULL, rarete INTEGER NOT NULL)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO emoji (id, nom, code, intelligence) SELECT id, name, code, intelligence FROM __temp__emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE __temp__emoji
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250530163653 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__emoji AS SELECT id, rarity_id, name, code, intelligence, strength, toughness, speed, fights_won FROM emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE emoji (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, rarity_id INTEGER NOT NULL, parent1_id INTEGER DEFAULT NULL, parent2_id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL, code VARCHAR(255) NOT NULL, intelligence DOUBLE PRECISION NOT NULL, strength DOUBLE PRECISION NOT NULL, toughness DOUBLE PRECISION NOT NULL, speed DOUBLE PRECISION NOT NULL, fights_won INTEGER NOT NULL, CONSTRAINT FK_B64BF632F3747573 FOREIGN KEY (rarity_id) REFERENCES rarity (id) ON UPDATE NO ACTION ON DELETE NO ACTION NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_B64BF632861B2665 FOREIGN KEY (parent1_id) REFERENCES emoji (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_B64BF63294AE898B FOREIGN KEY (parent2_id) REFERENCES emoji (id) NOT DEFERRABLE INITIALLY IMMEDIATE)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO emoji (id, rarity_id, name, code, intelligence, strength, toughness, speed, fights_won) SELECT id, rarity_id, name, code, intelligence, strength, toughness, speed, fights_won FROM __temp__emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE __temp__emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_B64BF632F3747573 ON emoji (rarity_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_B64BF632861B2665 ON emoji (parent1_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_B64BF63294AE898B ON emoji (parent2_id)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__emoji AS SELECT id, rarity_id, name, code, strength, toughness, intelligence, speed, fights_won FROM emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE emoji (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, rarity_id INTEGER NOT NULL, name VARCHAR(255) NOT NULL, code VARCHAR(255) NOT NULL, strength DOUBLE PRECISION NOT NULL, toughness DOUBLE PRECISION NOT NULL, intelligence DOUBLE PRECISION NOT NULL, speed DOUBLE PRECISION NOT NULL, fights_won INTEGER NOT NULL, CONSTRAINT FK_B64BF632F3747573 FOREIGN KEY (rarity_id) REFERENCES rarity (id) NOT DEFERRABLE INITIALLY IMMEDIATE)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO emoji (id, rarity_id, name, code, strength, toughness, intelligence, speed, fights_won) SELECT id, rarity_id, name, code, strength, toughness, intelligence, speed, fights_won FROM __temp__emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE __temp__emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_B64BF632F3747573 ON emoji (rarity_id)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250610074721 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE stock_emoji (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, code VARCHAR(255) NOT NULL, name VARCHAR(255) NOT NULL)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE user (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, username VARCHAR(180) NOT NULL, roles CLOB NOT NULL --(DC2Type:json)
|
||||||
|
, password VARCHAR(255) NOT NULL)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE UNIQUE INDEX UNIQ_8D93D649F85E0677 ON user (username)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE posseder (user_id INTEGER NOT NULL, emoji_id INTEGER NOT NULL, PRIMARY KEY(user_id, emoji_id), CONSTRAINT FK_62EF7CBAA76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT FK_62EF7CBAE2462A5B FOREIGN KEY (emoji_id) REFERENCES emoji (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_62EF7CBAA76ED395 ON posseder (user_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE INDEX IDX_62EF7CBAE2462A5B ON posseder (emoji_id)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__rarity AS SELECT id, name, drop_rate FROM rarity
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE rarity
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE rarity (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, name VARCHAR(50) NOT NULL, drop_rate DOUBLE PRECISION NOT NULL)
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO rarity (id, name, drop_rate) SELECT id, name, drop_rate FROM __temp__rarity
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE __temp__rarity
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE UNIQUE INDEX UNIQ_B7C0BE465E237E06 ON rarity (name)
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE stock_emoji
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE user
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE posseder
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TEMPORARY TABLE __temp__rarity AS SELECT id, name, drop_rate FROM rarity
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE rarity
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
CREATE TABLE rarity (id INTEGER DEFAULT NULL, name VARCHAR(255) NOT NULL, drop_rate DOUBLE PRECISION NOT NULL, PRIMARY KEY(id))
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
INSERT INTO rarity (id, name, drop_rate) SELECT id, name, drop_rate FROM __temp__rarity
|
||||||
|
SQL);
|
||||||
|
$this->addSql(<<<'SQL'
|
||||||
|
DROP TABLE __temp__rarity
|
||||||
|
SQL);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace DoctrineMigrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
|
use Doctrine\Migrations\AbstractMigration;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your needs!
|
||||||
|
*/
|
||||||
|
final class Version20250610074733 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function getDescription(): string
|
||||||
|
{
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function up(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this up() migration is auto-generated, please modify it to your needs
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema): void
|
||||||
|
{
|
||||||
|
// this down() migration is auto-generated, please modify it to your needs
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -1,90 +0,0 @@
|
|||||||
body {
|
|
||||||
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
|
|
||||||
background-color: #f4f6f8;
|
|
||||||
color: #333;
|
|
||||||
margin: 2rem auto;
|
|
||||||
max-width: 800px;
|
|
||||||
padding: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
h1 {
|
|
||||||
color: #2c3e50;
|
|
||||||
font-size: 2rem;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
text-align: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
h2 {
|
|
||||||
color: #34495e;
|
|
||||||
font-size: 1.4rem;
|
|
||||||
margin-top: 2rem;
|
|
||||||
margin-bottom: 1rem;
|
|
||||||
border-bottom: 2px solid #ccc;
|
|
||||||
padding-bottom: 0.2rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
section {
|
|
||||||
background: white;
|
|
||||||
border-radius: 8px;
|
|
||||||
padding: 1.5rem;
|
|
||||||
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.05);
|
|
||||||
margin-bottom: 1.5rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
ul#user-list {
|
|
||||||
list-style: none;
|
|
||||||
padding: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#user-list li {
|
|
||||||
background: #ecf0f1;
|
|
||||||
margin-bottom: 0.5rem;
|
|
||||||
padding: 0.8rem 1rem;
|
|
||||||
border-radius: 6px;
|
|
||||||
display: flex;
|
|
||||||
justify-content: space-between;
|
|
||||||
align-items: center;
|
|
||||||
}
|
|
||||||
|
|
||||||
#user-list li button {
|
|
||||||
background-color: #e74c3c;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
padding: 6px 12px;
|
|
||||||
border-radius: 4px;
|
|
||||||
cursor: pointer;
|
|
||||||
font-size: 0.9rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
#user-list li button:hover {
|
|
||||||
background-color: #c0392b;
|
|
||||||
}
|
|
||||||
|
|
||||||
form#add-user-form {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: column;
|
|
||||||
gap: 0.8rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
form#add-user-form input,
|
|
||||||
form#add-user-form select {
|
|
||||||
padding: 0.6rem;
|
|
||||||
border: 1px solid #bdc3c7;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 1rem;
|
|
||||||
}
|
|
||||||
|
|
||||||
form#add-user-form button {
|
|
||||||
background-color: #3498db;
|
|
||||||
color: white;
|
|
||||||
border: none;
|
|
||||||
padding: 0.7rem;
|
|
||||||
border-radius: 4px;
|
|
||||||
font-size: 1rem;
|
|
||||||
cursor: pointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
form#add-user-form button:hover {
|
|
||||||
background-color: #2980b9;
|
|
||||||
}
|
|
@ -1,98 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Controller;
|
|
||||||
|
|
||||||
use App\Entity\User;
|
|
||||||
use App\Repository\UserRepository;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
|
||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
||||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
|
|
||||||
|
|
||||||
#[Route('/admin', name: 'admin_')]
|
|
||||||
#[IsGranted('ROLE_ADMIN')]
|
|
||||||
class AdminController extends AbstractController
|
|
||||||
{
|
|
||||||
private EntityManagerInterface $entityManager;
|
|
||||||
private UserPasswordHasherInterface $passwordHasher;
|
|
||||||
|
|
||||||
public function __construct(EntityManagerInterface $entityManager, UserPasswordHasherInterface $passwordHasher)
|
|
||||||
{
|
|
||||||
$this->entityManager = $entityManager;
|
|
||||||
$this->passwordHasher = $passwordHasher;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('', name: 'admin_dashboard')]
|
|
||||||
public function dashboard(): Response
|
|
||||||
{
|
|
||||||
return $this->render('admin/index.html.twig');
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/users', name: 'users_list', methods: ['GET'])]
|
|
||||||
public function getUserById(UserRepository $userRepository): JsonResponse
|
|
||||||
{
|
|
||||||
$users = $userRepository->findAll();
|
|
||||||
|
|
||||||
$data = array_map(function (User $user) {
|
|
||||||
return [
|
|
||||||
'id' => $user->getId(),
|
|
||||||
'username' => $user->getUsername(),
|
|
||||||
'roles' => $user->getRoles(),
|
|
||||||
];
|
|
||||||
}, $users);
|
|
||||||
|
|
||||||
return $this->json($data);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/users/add', name: 'add_user', methods: ['POST'])]
|
|
||||||
public function addUser(Request $request, UserPasswordHasherInterface $passwordHasher): JsonResponse
|
|
||||||
{
|
|
||||||
$data = json_decode($request->getContent(), true);
|
|
||||||
|
|
||||||
$username = $data['username'] ?? null;
|
|
||||||
$password = $data['password'] ?? null;
|
|
||||||
$roles = $data['roles'] ?? ['ROLE_USER'];
|
|
||||||
|
|
||||||
if (!$username || !$password) {
|
|
||||||
return $this->json(['error' => 'Missing username or password'], Response::HTTP_BAD_REQUEST);
|
|
||||||
}
|
|
||||||
|
|
||||||
$existingUser = $this->entityManager->getRepository(User::class)->findOneBy(['username' => $username]);
|
|
||||||
if ($existingUser) {
|
|
||||||
return $this->json(['error' => 'User already exists'], Response::HTTP_CONFLICT);
|
|
||||||
}
|
|
||||||
|
|
||||||
$user = new User();
|
|
||||||
$user->setUsername($username);
|
|
||||||
$user->setRoles($roles);
|
|
||||||
$user->setPassword($passwordHasher->hashPassword($user, $password));
|
|
||||||
|
|
||||||
$this->entityManager->persist($user);
|
|
||||||
$this->entityManager->flush();
|
|
||||||
|
|
||||||
return $this->json(['message' => 'User created successfully', 'id' => $user->getId()], Response::HTTP_CREATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Route('/users/delete/{id}', name: 'delete_user', methods: ['DELETE'])]
|
|
||||||
public function deleteUser(int $id): JsonResponse
|
|
||||||
{
|
|
||||||
$user = $this->entityManager->getRepository(User::class)->find($id);
|
|
||||||
|
|
||||||
if (!$user) {
|
|
||||||
return $this->json(['error' => 'User not found'], Response::HTTP_NOT_FOUND);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($user->getEmojis() as $userEmoji) {
|
|
||||||
$this->entityManager->remove($userEmoji);
|
|
||||||
}
|
|
||||||
$this->entityManager->remove($user);
|
|
||||||
$this->entityManager->flush();
|
|
||||||
|
|
||||||
return $this->json(['message' => 'User and related data deleted successfully'], Response::HTTP_OK);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Entity;
|
|
||||||
|
|
||||||
use App\Repository\UserEmojisRepository;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
|
||||||
|
|
||||||
#[ORM\Entity(repositoryClass: UserEmojisRepository::class)]
|
|
||||||
class UserEmojis
|
|
||||||
{
|
|
||||||
#[ORM\Id]
|
|
||||||
#[ORM\GeneratedValue]
|
|
||||||
#[ORM\Column]
|
|
||||||
private ?int $id = null;
|
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: User::class)]
|
|
||||||
#[ORM\JoinColumn(nullable: false)]
|
|
||||||
private ?User $user = null;
|
|
||||||
|
|
||||||
#[ORM\ManyToOne(targetEntity: Emoji::class)]
|
|
||||||
#[ORM\JoinColumn(nullable: false)]
|
|
||||||
private ?Emoji $emoji = null;
|
|
||||||
|
|
||||||
public function getId(): ?int
|
|
||||||
{
|
|
||||||
return $this->id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getUser(): ?User
|
|
||||||
{
|
|
||||||
return $this->user;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setUser(?User $user): static
|
|
||||||
{
|
|
||||||
$this->user = $user;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEmoji(): ?Emoji
|
|
||||||
{
|
|
||||||
return $this->emoji;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setEmoji(?Emoji $emoji): static
|
|
||||||
{
|
|
||||||
$this->emoji = $emoji;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,48 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Repository;
|
|
||||||
|
|
||||||
use App\Entity\UserEmojis;
|
|
||||||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @extends ServiceEntityRepository<UserEmojis>
|
|
||||||
*
|
|
||||||
* @method UserEmojis|null find($id, $lockMode = null, $lockVersion = null)
|
|
||||||
* @method UserEmojis|null findOneBy(array $criteria, array $orderBy = null)
|
|
||||||
* @method UserEmojis[] findAll()
|
|
||||||
* @method UserEmojis[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
|
|
||||||
*/
|
|
||||||
class UserEmojisRepository extends ServiceEntityRepository
|
|
||||||
{
|
|
||||||
public function __construct(ManagerRegistry $registry)
|
|
||||||
{
|
|
||||||
parent::__construct($registry, UserEmojis::class);
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * @return UserEmojis[] Returns an array of UserEmojis objects
|
|
||||||
// */
|
|
||||||
// public function findByExampleField($value): array
|
|
||||||
// {
|
|
||||||
// return $this->createQueryBuilder('u')
|
|
||||||
// ->andWhere('u.exampleField = :val')
|
|
||||||
// ->setParameter('val', $value)
|
|
||||||
// ->orderBy('u.id', 'ASC')
|
|
||||||
// ->setMaxResults(10)
|
|
||||||
// ->getQuery()
|
|
||||||
// ->getResult()
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public function findOneBySomeField($value): ?UserEmojis
|
|
||||||
// {
|
|
||||||
// return $this->createQueryBuilder('u')
|
|
||||||
// ->andWhere('u.exampleField = :val')
|
|
||||||
// ->setParameter('val', $value)
|
|
||||||
// ->getQuery()
|
|
||||||
// ->getOneOrNullResult()
|
|
||||||
// ;
|
|
||||||
// }
|
|
||||||
}
|
|
@ -1,104 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Service;
|
|
||||||
|
|
||||||
use App\Entity\Emoji;
|
|
||||||
use App\Entity\User;
|
|
||||||
use App\Entity\UserEmojis;
|
|
||||||
use App\Entity\Rarity;
|
|
||||||
use App\Repository\StockEmojiRepository;
|
|
||||||
use App\Repository\RarityRepository;
|
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
|
||||||
|
|
||||||
class EmojiService
|
|
||||||
{
|
|
||||||
private $entityManager;
|
|
||||||
private $stockEmojiRepository;
|
|
||||||
private $rarityRepository;
|
|
||||||
|
|
||||||
public function __construct(
|
|
||||||
EntityManagerInterface $entityManager,
|
|
||||||
StockEmojiRepository $stockEmojiRepository,
|
|
||||||
RarityRepository $rarityRepository
|
|
||||||
) {
|
|
||||||
$this->entityManager = $entityManager;
|
|
||||||
$this->stockEmojiRepository = $stockEmojiRepository;
|
|
||||||
$this->rarityRepository = $rarityRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addRandomStockEmojisToUser(User $user, int $numberOfEmojis = 4): void
|
|
||||||
{
|
|
||||||
$stockEmojis = $this->stockEmojiRepository->findAll();
|
|
||||||
|
|
||||||
if (count($stockEmojis) < $numberOfEmojis) {
|
|
||||||
throw new \RuntimeException('Not enough emojis in stock.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$randomEmojis = $this->getRandomEmojis($stockEmojis, $numberOfEmojis);
|
|
||||||
|
|
||||||
foreach ($randomEmojis as $stockEmoji) {
|
|
||||||
$emoji = new Emoji();
|
|
||||||
$emoji->setName($stockEmoji->getName());
|
|
||||||
$emoji->setCode($stockEmoji->getCode());
|
|
||||||
$emoji->setStrength(mt_rand(0, 10));
|
|
||||||
$emoji->setToughness(mt_rand(0, 10));
|
|
||||||
$emoji->setIntelligence(mt_rand(0, 10));
|
|
||||||
$emoji->setSpeed(mt_rand(0, 10));
|
|
||||||
$emoji->setFightsWon(0);
|
|
||||||
|
|
||||||
// Set the rarity
|
|
||||||
$rarity = $this->generateRarity();
|
|
||||||
$emoji->setRarity($rarity);
|
|
||||||
|
|
||||||
$this->entityManager->persist($emoji);
|
|
||||||
|
|
||||||
$userEmoji = new UserEmojis();
|
|
||||||
$userEmoji->setUser($user);
|
|
||||||
$userEmoji->setEmoji($emoji);
|
|
||||||
|
|
||||||
$this->entityManager->persist($userEmoji);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->entityManager->flush();
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getRandomEmojis(array $stockEmojis, int $count): array
|
|
||||||
{
|
|
||||||
shuffle($stockEmojis);
|
|
||||||
return array_slice($stockEmojis, 0, $count);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function generateRarity(): Rarity
|
|
||||||
{
|
|
||||||
$rarities = $this->rarityRepository->findAll();
|
|
||||||
$rand = mt_rand() / mt_getrandmax();
|
|
||||||
|
|
||||||
$sum = 0.0;
|
|
||||||
foreach ($rarities as $rarity) {
|
|
||||||
$sum += $rarity->getDropRate();
|
|
||||||
if ($sum > $rand) {
|
|
||||||
return $rarity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rarities[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getEmojisByUser(User $user): array
|
|
||||||
{
|
|
||||||
return $user->getEmojis()->map(function ($userEmoji) {
|
|
||||||
$emoji = $userEmoji->getEmoji();
|
|
||||||
return [
|
|
||||||
'id' => $emoji->getId(),
|
|
||||||
'name' => $emoji->getName(),
|
|
||||||
'code' => $emoji->getCode(),
|
|
||||||
'strength' => $emoji->getStrength(),
|
|
||||||
'toughness' => $emoji->getToughness(),
|
|
||||||
'intelligence' => $emoji->getIntelligence(),
|
|
||||||
'speed' => $emoji->getSpeed(),
|
|
||||||
'fightsWon' => $emoji->getFightsWon(),
|
|
||||||
'rarity' => $emoji->getRarity() ? $emoji->getRarity()->getId() : 0,
|
|
||||||
];
|
|
||||||
})->toArray();
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue