Bladeren bron

add and complete entities

olinox14 2 maanden geleden
bovenliggende
commit
5c18d25e00

+ 64 - 0
api/src/Entity/Galaxy.php

@@ -0,0 +1,64 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity;
+
+use ApiPlatform\Metadata\ApiResource;
+use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\Common\Collections\Collection;
+use Doctrine\ORM\Mapping as ORM;
+
+#[ORM\Entity]
+#[ApiResource]
+class Galaxy
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 100, unique: true, nullable: false)]
+    private string $name;
+
+    /** @var Collection<int, Sector> */
+    #[ORM\OneToMany(targetEntity: Sector::class, mappedBy: 'galaxy', orphanRemoval: true)]
+    private Collection $sectors;
+
+    public function __construct()
+    {
+        $this->sectors = 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 getSectors(): Collection
+    {
+        return $this->sectors;
+    }
+
+    public function setSectors(Collection $sectors): self
+    {
+        $this->sectors = $sectors;
+        return $this;
+    }
+}

+ 56 - 13
api/src/Entity/Game.php

@@ -1,13 +1,14 @@
 <?php
 declare(strict_types=1);
 
-namespace App\Entity\User;
+namespace App\Entity;
 
 use ApiPlatform\Metadata\ApiResource;
+use App\Enum\GameStatusEnum;
 use Doctrine\Common\Collections\ArrayCollection;
 use Doctrine\Common\Collections\Collection;
+use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
-use Symfony\Component\Validator\Constraints as Assert;
 
 #[ORM\Entity]
 #[ApiResource]
@@ -21,12 +22,21 @@ class Game
     #[ORM\Column(length: 100, unique: true, nullable: false)]
     private string $name;
 
-    #[ORM\OneToMany(targetEntity: GameParticipation::class, mappedBy: 'game', cascade: ['persist', 'remove'])]
-    private Collection $gameParticipations;
+    #[ORM\OneToMany(targetEntity: Player::class, mappedBy: 'game', cascade: ['persist', 'remove'])]
+    private Collection $players;
+
+    #[ORM\OneToOne(targetEntity: Galaxy::class, mappedBy: 'game', cascade: ['persist', 'remove'])]
+    private ?Galaxy $galaxy = null;
+
+    #[ORM\Column(length: 24, enumType: GameStatusEnum::class, options: ['default' => GameStatusEnum::DRAFT])]
+    private GameStatusEnum $status = GameStatusEnum::DRAFT;
+
+    #[ORM\Column(type: Types::DATETIME_IMMUTABLE, nullable: true)]
+    private ?\DateTimeImmutable $openedAt = null;
 
     public function __construct()
     {
-        $this->gameParticipations = new ArrayCollection();
+        $this->players = new ArrayCollection();
     }
 
     public function getId(): ?int
@@ -51,24 +61,57 @@ class Game
         return $this;
     }
 
-    public function getGameParticipations(): Collection
+    public function getPlayers(): Collection
     {
-        return $this->gameParticipations;
+        return $this->players;
     }
 
-    public function addGameParticipation(GameParticipation $gameParticipation): self
+    public function addPlayer(Player $player): self
     {
-        if (!$this->gameParticipations->contains($gameParticipation)) {
-            $this->gameParticipations->add($gameParticipation);
-            $gameParticipation->setGame($this);
+        if (!$this->players->contains($player)) {
+            $this->players->add($player);
+            $player->setGame($this);
         }
 
         return $this;
     }
 
-    public function removeGameParticipation(GameParticipation $gameParticipation): self
+    public function removePlayer(Player $player): self
+    {
+        $this->players->removeElement($player);
+        return $this;
+    }
+
+    public function getGalaxy(): ?Galaxy
+    {
+        return $this->galaxy;
+    }
+
+    public function setGalaxy(?Galaxy $galaxy): self
+    {
+        $this->galaxy = $galaxy;
+        return $this;
+    }
+
+    public function getOpenedAt(): ?\DateTimeImmutable
+    {
+        return $this->openedAt;
+    }
+
+    public function setOpenedAt(?\DateTimeImmutable $openedAt): self
+    {
+        $this->openedAt = $openedAt;
+        return $this;
+    }
+
+    public function getStatus(): GameStatusEnum
+    {
+        return $this->status;
+    }
+
+    public function setStatus(GameStatusEnum $status): self
     {
-        $this->gameParticipations->removeElement($gameParticipation);
+        $this->status = $status;
         return $this;
     }
 }

+ 91 - 0
api/src/Entity/Planet.php

@@ -0,0 +1,91 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity;
+
+use ApiPlatform\Metadata\ApiResource;
+use App\Enum\CelestialBodySizeEnum;
+use App\Enum\PlanetTypeEnum;
+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 Planet
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 100, nullable: false)]
+    private string $name;
+
+    #[ORM\Column(length: 24, enumType: PlanetTypeEnum::class, options: ['default' => PlanetTypeEnum::UNINHABITABLE])]
+    private PlanetTypeEnum $type;
+
+    #[ORM\Column(nullable: true)]
+    #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 1, max: 7)]
+    private ?int $position = null;
+
+    #[ORM\Column(length: 3, enumType: CelestialBodySizeEnum::class, options: ['default' => CelestialBodySizeEnum::M])]
+    private CelestialBodySizeEnum $size = CelestialBodySizeEnum::M;
+
+    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 getType(): PlanetTypeEnum
+    {
+        return $this->type;
+    }
+
+    public function setType(PlanetTypeEnum $type): self
+    {
+        $this->type = $type;
+        return $this;
+    }
+
+    public function getPosition(): ?int
+    {
+        return $this->position;
+    }
+
+    public function setPosition(?int $position): self
+    {
+        $this->position = $position;
+        return $this;
+    }
+
+    public function getSize(): CelestialBodySizeEnum
+    {
+        return $this->size;
+    }
+
+    public function setSize(CelestialBodySizeEnum $size): self
+    {
+        $this->size = $size;
+        return $this;
+    }
+}

+ 34 - 4
api/src/Entity/Player.php

@@ -4,14 +4,16 @@ declare(strict_types=1);
 namespace App\Entity;
 
 use ApiPlatform\Metadata\ApiResource;
+use App\Enum\CareerEnum;
+use App\Enum\PlayerStatusEnum;
 use Doctrine\DBAL\Types\Types;
 use Doctrine\ORM\Mapping as ORM;
 
 #[ORM\Entity]
-#[ORM\Table(name: 'game_participations')]
+#[ORM\Table(name: 'player')]
 #[ORM\UniqueConstraint(name: 'unique_user_game', columns: ['user_id', 'game_id'])]
 #[ApiResource]
-class GameParticipation
+class Player
 {
     #[ORM\Id]
     #[ORM\GeneratedValue]
@@ -26,11 +28,17 @@ class GameParticipation
     #[ORM\JoinColumn(nullable: false)]
     private Game $game;
 
+    #[ORM\Column(length: 100, nullable: false)]
+    private string $name;
+
+    #[ORM\Column(length: 24, enumType: CareerEnum::class, options: ['default' => CareerEnum::CORPORATION_EMPLOYEE])]
+    private CareerEnum $career = CareerEnum::CORPORATION_EMPLOYEE;
+
     #[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
     private \DateTimeImmutable $joinedAt;
 
-    #[ORM\Column(length: 20, nullable: false, options: ['default' => 'active'])]
-    private string $status = 'active';
+    #[ORM\Column(length: 24, enumType: PlayerStatusEnum::class, options: ['default' => PlayerStatusEnum::ACTIVE])]
+    private PlayerStatusEnum $status = PlayerStatusEnum::ACTIVE;
 
     #[ORM\Column(nullable: true)]
     private ?int $score = null;
@@ -70,6 +78,28 @@ class GameParticipation
         return $this;
     }
 
+    public function getName(): string
+    {
+        return $this->name;
+    }
+
+    public function setName(string $name): self
+    {
+        $this->name = $name;
+        return $this;
+    }
+
+    public function getCareer(): CareerEnum
+    {
+        return $this->career;
+    }
+
+    public function setCareer(CareerEnum $career): self
+    {
+        $this->career = $career;
+        return $this;
+    }
+
     public function getJoinedAt(): \DateTimeImmutable
     {
         return $this->joinedAt;

+ 81 - 0
api/src/Entity/Sector.php

@@ -0,0 +1,81 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity;
+
+use ApiPlatform\Metadata\ApiResource;
+use App\Enum\SectorStatusEnum;
+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 Sector
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 100, nullable: false)]
+    private string $name;
+
+    /** @var Collection<int, System> */
+    #[ORM\OneToMany(targetEntity: System::class, mappedBy: 'sector', orphanRemoval: true)]
+    private Collection $systems;
+
+    #[ORM\Column(length: 24, enumType: SectorStatusEnum::class, options: ['default' => SectorStatusEnum::UNEXPLORED])]
+    private SectorStatusEnum $status = SectorStatusEnum::UNEXPLORED;
+
+    public function __construct()
+    {
+        $this->systems = 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 getSystems(): Collection
+    {
+        return $this->systems;
+    }
+
+    public function setSystems(Collection $systems): self
+    {
+        $this->systems = $systems;
+        return $this;
+    }
+
+    public function getStatus(): SectorStatusEnum
+    {
+        return $this->status;
+    }
+
+    public function setStatus(SectorStatusEnum $status): self
+    {
+        $this->status = $status;
+        return $this;
+    }
+}

+ 111 - 0
api/src/Entity/System.php

@@ -0,0 +1,111 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Entity;
+
+use ApiPlatform\Metadata\ApiResource;
+use App\Enum\CelestialBodySizeEnum;
+use App\Enum\StarTypeEnum;
+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 System
+{
+    #[ORM\Id]
+    #[ORM\GeneratedValue]
+    #[ORM\Column]
+    private ?int $id = null;
+
+    #[ORM\Column(length: 100, nullable: false)]
+    private string $name;
+
+    /** @var Collection<int, Planet> */
+    #[ORM\OneToMany(targetEntity: Planet::class, mappedBy: 'system', orphanRemoval: true)]
+    private Collection $planets;
+
+    #[ORM\Column(length: 20, enumType: StarTypeEnum::class, options: ['default' => StarTypeEnum::RED_DWARF])]
+    private StarTypeEnum $starType = StarTypeEnum::RED_DWARF;
+
+    #[ORM\Column(length: 3, enumType: CelestialBodySizeEnum::class, options: ['default' => CelestialBodySizeEnum::M])]
+    private CelestialBodySizeEnum $starSize = CelestialBodySizeEnum::M;
+
+    #[ORM\Column(nullable: true)]
+    #[Assert\Range(notInRangeMessage: 'between_{{ min }}_and_{{ max }}', min: 0, max: 7)]
+    private int $asteroidBeltPosition = 0;
+
+    public function __construct()
+    {
+        $this->planets = 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 getPlanets(): Collection
+    {
+        return $this->planets;
+    }
+
+    public function setPlanets(Collection $planets): self
+    {
+        $this->planets = $planets;
+        return $this;
+    }
+
+    public function getStarType(): StarTypeEnum
+    {
+        return $this->starType;
+    }
+
+    public function setStarType(StarTypeEnum $starType): self
+    {
+        $this->starType = $starType;
+        return $this;
+    }
+
+    public function getStarSize(): CelestialBodySizeEnum
+    {
+        return $this->starSize;
+    }
+
+    public function setStarSize(CelestialBodySizeEnum $starSize): self
+    {
+        $this->starSize = $starSize;
+        return $this;
+    }
+
+    public function getAsteroidBeltPosition(): int
+    {
+        return $this->asteroidBeltPosition;
+    }
+
+    public function setAsteroidBeltPosition(int $asteroidBeltPosition): self
+    {
+        $this->asteroidBeltPosition = $asteroidBeltPosition;
+        return $this;
+    }
+}

+ 13 - 13
api/src/Entity/User.php

@@ -1,11 +1,11 @@
 <?php
 declare(strict_types=1);
 
-namespace App\Entity\User;
+namespace App\Entity;
 
 use ApiPlatform\Metadata\ApiResource;
-use Doctrine\Common\Collections\Collection;
 use Doctrine\Common\Collections\ArrayCollection;
+use Doctrine\Common\Collections\Collection;
 use Doctrine\ORM\Mapping as ORM;
 use Symfony\Component\Validator\Constraints as Assert;
 
@@ -28,12 +28,12 @@ class User
     #[ORM\Column(length: 100, nullable: false)]
     private string $password;
 
-    #[ORM\OneToMany(mappedBy: 'user', targetEntity: GameParticipation::class, cascade: ['persist', 'remove'])]
-    private Collection $gameParticipations;
+    #[ORM\OneToMany(targetEntity: Player::class, mappedBy: 'user', cascade: ['persist', 'remove'])]
+    private Collection $players;
 
     public function __construct()
     {
-        $this->gameParticipations = new ArrayCollection();
+        $this->players = new ArrayCollection();
     }
 
     public function getId(): ?int
@@ -80,24 +80,24 @@ class User
         return $this;
     }
 
-    public function getGameParticipations(): Collection
+    public function getPlayers(): Collection
     {
-        return $this->gameParticipations;
+        return $this->players;
     }
 
-    public function addGameParticipation(GameParticipation $gameParticipation): self
+    public function addPlayer(Player $player): self
     {
-        if (!$this->gameParticipations->contains($gameParticipation)) {
-            $this->gameParticipations->add($gameParticipation);
-            $gameParticipation->setUser($this);
+        if (!$this->players->contains($player)) {
+            $this->players->add($player);
+            $player->setUser($this);
         }
 
         return $this;
     }
 
-    public function removeGameParticipation(GameParticipation $gameParticipation): self
+    public function removePlayer(Player $player): self
     {
-        $this->gameParticipations->removeElement($gameParticipation);
+        $this->players->removeElement($player);
         return $this;
     }
 }

+ 11 - 0
api/src/Enum/CareerEnum.php

@@ -0,0 +1,11 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Enum;
+
+enum CareerEnum: string
+{
+    case CORPORATION_EMPLOYEE = 'CORPORATION_EMPLOYEE';
+    case INDEPENDANT = 'INDEPENDANT';
+    case PIRATE = 'PIRATE';
+}

+ 14 - 0
api/src/Enum/CelestialBodySizeEnum.php

@@ -0,0 +1,14 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Enum;
+
+enum CelestialBodySizeEnum: string
+{
+    case XS = 'XS';
+    case S = 'S';
+    case M = 'M';
+    case L = 'L';
+    case XL = 'XL';
+    case XXL = 'XXL';
+}

+ 11 - 0
api/src/Enum/GameStatusEnum.php

@@ -0,0 +1,11 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Enum;
+
+enum GameStatusEnum: string
+{
+    case DRAFT = 'DRAFT';
+    case OPEN = 'OPEN';
+    case CLOSED = 'CLOSED';
+}

+ 11 - 0
api/src/Enum/PlanetTypeEnum.php

@@ -0,0 +1,11 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Enum;
+
+enum PlanetTypeEnum: string
+{
+    case INHABITABLE = 'INHABITABLE';
+    case TERRAFORMABLE = 'TERRAFORMABLE';
+    case UNINHABITABLE = 'UNINHABITABLE';
+}

+ 10 - 0
api/src/Enum/PlayerStatusEnum.php

@@ -0,0 +1,10 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Enum;
+
+enum PlayerStatusEnum: string
+{
+    case ACTIVE = 'ACTIVE';
+    case INACTIVE = 'INACTIVE';
+}

+ 11 - 0
api/src/Enum/SectorStatusEnum.php

@@ -0,0 +1,11 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Enum;
+
+enum SectorStatusEnum: string
+{
+    case CENTRAL = 'CENTRAL';
+    case EXPLORED = 'EXPLORED';
+    case UNEXPLORED = 'UNEXPLORED';
+}

+ 15 - 0
api/src/Enum/StarTypeEnum.php

@@ -0,0 +1,15 @@
+<?php
+declare(strict_types=1);
+
+namespace App\Enum;
+
+enum StarTypeEnum: string
+{
+    case RED_DWARF = 'RED_DWARF';
+    case ORANGE_DWARF = 'ORANGE_DWARF';
+    case YELLOW_DWARF = 'YELLOW_DWARF';
+    case SUB_GIANT = 'SUB_GIANT';
+    case F_STAR = 'F_STAR';
+    case A_STAR = 'G_STAR';
+    case T_STAR = 'K_STAR';
+}