Procházet zdrojové kódy

add basic entities

olinox14 před 2 měsíci
rodič
revize
4aa81d370c

+ 0 - 67
api/src/Entity/Author.php

@@ -1,67 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace App\Entity;
-
-use ApiPlatform\Metadata\ApiResource;
-use ApiPlatform\Metadata\Get;
-use Doctrine\ORM\Mapping as ORM;
-use Doctrine\Common\Collections\Collection;
-
-#[ORM\Entity]
-#[ApiResource]
-class Author
-{
-    #[ORM\Id]
-    #[ORM\GeneratedValue]
-    #[ORM\Column]
-    private ?int $id = null;
-
-    #[ORM\Column(length: 100, nullable: false)]
-    private string $name;
-
-    #[ORM\OneToMany(targetEntity: Song::class, mappedBy: 'author', cascade: ['persist', 'remove'])]
-    private Collection $songs;
-
-    public function getId(): ?int
-    {
-        return $this->id;
-    }
-
-    public function setId(?int $id): self
-    {
-        $this->id = $id;
-        return $this;
-    }
-
-    public function getName(): string
-    {
-        return $this->name;
-    }
-
-    public function setName(string $name): self
-    {
-        $this->name = $name;
-        return $this;
-    }
-
-    public function getSongs(): Collection
-    {
-        return $this->songs;
-    }
-
-    public function addSong(Song $songs): self
-    {
-        if (!$this->songs->contains($songs)) {
-            $this->songs[] = $songs;
-            $songs->setAuthor($this);
-        }
-
-        return $this;
-    }
-
-    public function removeSong(Song $songs): self {
-        $this->songs->removeElement($songs);
-        return $this;
-    }
-}

+ 0 - 60
api/src/Entity/Song.php

@@ -1,60 +0,0 @@
-<?php
-declare(strict_types=1);
-
-namespace App\Entity;
-
-use ApiPlatform\Metadata\ApiResource;
-use ApiPlatform\Metadata\ApiFilter;
-use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
-use Doctrine\ORM\Mapping as ORM;
-use Symfony\Component\Serializer\Annotation\Groups;
-
-#[ORM\Entity]
-#[ApiResource]
-#[ApiFilter(SearchFilter::class, properties: ['author' => 'exact'])]
-class Song
-{
-    #[ORM\Id]
-    #[ORM\GeneratedValue]
-    #[ORM\Column]
-    private ?int $id = null;
-
-    #[ORM\Column(length: 100, nullable: false)]
-    private string $title;
-
-    #[ORM\ManyToOne(inversedBy: 'songs')]
-    private Author $author;
-
-    public function getId(): ?int
-    {
-        return $this->id;
-    }
-
-    public function setId(?int $id): self
-    {
-        $this->id = $id;
-        return $this;
-    }
-
-    public function getTitle(): string
-    {
-        return $this->title;
-    }
-
-    public function setTitle(string $title): self
-    {
-        $this->title = $title;
-        return $this;
-    }
-
-    public function getAuthor(): Author
-    {
-        return $this->author;
-    }
-
-    public function setAuthor(Author $author): self
-    {
-        $this->author = $author;
-        return $this;
-    }
-}

+ 74 - 0
api/src/Entity/User/Game.php

@@ -0,0 +1,74 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity\User;
+
+use ApiPlatform\Metadata\ApiResource;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\Common\Collections\Collection;
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
+
+#[ORM\Entity]
+#[ApiResource]
+class Game
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 100, unique: true, nullable: false)]
+    private string $name;
+
+    #[ORM\OneToMany(targetEntity: GameParticipation::class, mappedBy: 'game', cascade: ['persist', 'remove'])]
+    private Collection $gameParticipations;
+
+    public function __construct()
+    {
+        $this->gameParticipations = new ArrayCollection();
+    }
+
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    public function setId(?int $id): self
+    {
+        $this->id = $id;
+        return $this;
+    }
+
+    public function getName(): string
+    {
+        return $this->name;
+    }
+
+    public function setName(string $name): self
+    {
+        $this->name = $name;
+        return $this;
+    }
+
+    public function getGameParticipations(): Collection
+    {
+        return $this->gameParticipations;
+    }
+
+    public function addGameParticipation(GameParticipation $gameParticipation): self
+    {
+        if (!$this->gameParticipations->contains($gameParticipation)) {
+            $this->gameParticipations->add($gameParticipation);
+            $gameParticipation->setGame($this);
+        }
+
+        return $this;
+    }
+
+    public function removeGameParticipation(GameParticipation $gameParticipation): self
+    {
+        $this->gameParticipations->removeElement($gameParticipation);
+        return $this;
+    }
+}

+ 116 - 0
api/src/Entity/User/GameParticipation.php

@@ -0,0 +1,116 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity\User;
+
+use ApiPlatform\Metadata\ApiResource;
+use Doctrine\DBAL\Types\Types;
+use Doctrine\ORM\Mapping as ORM;
+
+#[ORM\Entity]
+#[ORM\Table(name: 'game_participations')]
+#[ORM\UniqueConstraint(name: 'unique_user_game', columns: ['user_id', 'game_id'])]
+#[ApiResource]
+class GameParticipation
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\ManyToOne(targetEntity: User::class, inversedBy: 'gameParticipations')]
+    #[ORM\JoinColumn(nullable: false)]
+    private User $user;
+
+    #[ORM\ManyToOne(targetEntity: Game::class, inversedBy: 'gameParticipations')]
+    #[ORM\JoinColumn(nullable: false)]
+    private Game $game;
+
+    #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
+    private \DateTimeImmutable $joinedAt;
+
+    #[ORM\Column(length: 20, nullable: false, options: ['default' => 'active'])]
+    private string $status = 'active';
+
+    #[ORM\Column(nullable: true)]
+    private ?int $score = null;
+
+    #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
+    private ?\DateTimeImmutable $lastPlayedAt = null;
+
+    public function __construct()
+    {
+        $this->joinedAt = new \DateTimeImmutable();
+    }
+
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    public function getUser(): User
+    {
+        return $this->user;
+    }
+
+    public function setUser(User $user): self
+    {
+        $this->user = $user;
+        return $this;
+    }
+
+    public function getGame(): Game
+    {
+        return $this->game;
+    }
+
+    public function setGame(Game $game): self
+    {
+        $this->game = $game;
+        return $this;
+    }
+
+    public function getJoinedAt(): \DateTimeImmutable
+    {
+        return $this->joinedAt;
+    }
+
+    public function setJoinedAt(\DateTimeImmutable $joinedAt): self
+    {
+        $this->joinedAt = $joinedAt;
+        return $this;
+    }
+
+    public function getStatus(): string
+    {
+        return $this->status;
+    }
+
+    public function setStatus(string $status): self
+    {
+        $this->status = $status;
+        return $this;
+    }
+
+    public function getScore(): ?int
+    {
+        return $this->score;
+    }
+
+    public function setScore(?int $score): self
+    {
+        $this->score = $score;
+        return $this;
+    }
+
+    public function getLastPlayedAt(): ?\DateTimeImmutable
+    {
+        return $this->lastPlayedAt;
+    }
+
+    public function setLastPlayedAt(?\DateTimeImmutable $lastPlayedAt): self
+    {
+        $this->lastPlayedAt = $lastPlayedAt;
+        return $this;
+    }
+}

+ 103 - 0
api/src/Entity/User/User.php

@@ -0,0 +1,103 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity\User;
+
+use ApiPlatform\Metadata\ApiResource;
+use Doctrine\Common\Collections\Collection;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\ORM\Mapping as ORM;
+use Symfony\Component\Validator\Constraints as Assert;
+
+#[ORM\Entity]
+#[ApiResource]
+class User
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 100, unique: true, nullable: false)]
+    private string $username;
+
+    #[ORM\Column(length: 255, unique: true, nullable: false)]
+    #[Assert\Email(message: 'invalid-email-format', mode: 'strict')]
+    private string $email;
+
+    #[ORM\Column(length: 100, nullable: false)]
+    private string $password;
+
+    #[ORM\OneToMany(mappedBy: 'user', targetEntity: GameParticipation::class, cascade: ['persist', 'remove'])]
+    private Collection $gameParticipations;
+
+    public function __construct()
+    {
+        $this->gameParticipations = new ArrayCollection();
+    }
+
+    public function getId(): ?int
+    {
+        return $this->id;
+    }
+
+    public function setId(?int $id): self
+    {
+        $this->id = $id;
+        return $this;
+    }
+
+    public function getUsername(): string
+    {
+        return $this->username;
+    }
+
+    public function setUsername(string $username): self
+    {
+        $this->username = $username;
+        return $this;
+    }
+
+    public function getEmail(): string
+    {
+        return $this->email;
+    }
+
+    public function setEmail(string $email): self
+    {
+        $this->email = $email;
+        return $this;
+    }
+
+    public function getPassword(): string
+    {
+        return $this->password;
+    }
+
+    public function setPassword(string $password): self
+    {
+        $this->password = $password;
+        return $this;
+    }
+
+    public function getGameParticipations(): Collection
+    {
+        return $this->gameParticipations;
+    }
+
+    public function addGameParticipation(GameParticipation $gameParticipation): self
+    {
+        if (!$this->gameParticipations->contains($gameParticipation)) {
+            $this->gameParticipations->add($gameParticipation);
+            $gameParticipation->setUser($this);
+        }
+
+        return $this;
+    }
+
+    public function removeGameParticipation(GameParticipation $gameParticipation): self
+    {
+        $this->gameParticipations->removeElement($gameParticipation);
+        return $this;
+    }
+}