diff --git a/symfony5/config/services_test.yaml b/symfony5/config/services_test.yaml index 2f60a1d..9174254 100755 --- a/symfony5/config/services_test.yaml +++ b/symfony5/config/services_test.yaml @@ -30,7 +30,7 @@ services: # add more service definitions when explicit configuration is needed # please note that last definitions always *replace* previous ones - #12 - test.App\Service\GameCreatorService: - alias: App\Service\GameCreatorService - public: true + #14 + test.App\Interfaces\IGameRepo: + alias: App\Interfaces\IGameRepo + public: true \ No newline at end of file diff --git a/symfony5/src/Entity/Game.php b/symfony5/src/Entity/Game.php index 1286fba..7c98467 100644 --- a/symfony5/src/Entity/Game.php +++ b/symfony5/src/Entity/Game.php @@ -9,6 +9,10 @@ use Swagger\Annotations as SWG; use Symfony\Component\Serializer\Annotation\Groups; +/** + * @ORM\Entity(repositoryClass="App\Repository\GameRepository") + * @ORM\Table(name="`game`") + */ class Game { const DRAFT = 'draft'; @@ -40,10 +44,19 @@ class Game const HEIGHT = 'height'; const HEIGHT_WIDTH = 'height_width'; const MOVE_CNT_TO_WIN = 'move_cnt_to_win'; + + /** + * @ORM\Id() + * @ORM\GeneratedValue() + * @ORM\Column(type="integer") + * @SWG\Property(property="id", type="integer", example=1) + * @Groups({"PUB"}) + */ + private int $id; /** - * @ORM\Column(type="string") - * @SWG\Property(property="status", type="string", example="ongoing", nullable=true) + * @ORM\Column(type="string", nullable=true) + * @SWG\Property(property="status", type="string", example="ongoing") * @Groups({"CREATE", "PUB", "ID_ERROR"}) */ private ?string $status = null; diff --git a/symfony5/src/Interfaces/IGameRepo.php b/symfony5/src/Interfaces/IGameRepo.php index 890b49a..c244ecd 100644 --- a/symfony5/src/Interfaces/IGameRepo.php +++ b/symfony5/src/Interfaces/IGameRepo.php @@ -10,16 +10,13 @@ public function setBoardDimensions(Game $item, int $width, int $height): Game; public function setRules(Game $item, int $moveCntToWin): Game; -// public function insertDraftIfNotExist(int $customerId): Order; -// -// public function getCurrentDraft(int $customerId): ?Order; -// -// public function setOrderCostsFromCartItems(Order $order): bool; -// -// public function fillShipping(Order $order, array $shippingData): Order; -// -// public function save(); -// + public function insertDraftIfNotExist(): Game; + public function getCurrentDraft(): ?Game; + public function mustFindCurrentDraft(): ?Game; + + + public function save(); + // public function markAsCompleted(Order $order): Order; // // public function mustFindUsersOrder(int $userId, int $orderId): Order; diff --git a/symfony5/src/Repository/GameRepository.php b/symfony5/src/Repository/GameRepository.php index e046a71..4433774 100644 --- a/symfony5/src/Repository/GameRepository.php +++ b/symfony5/src/Repository/GameRepository.php @@ -50,16 +50,14 @@ public function setRules(Game $item, int $moveCntToWin): Game */ public function insertDraftIfNotExist(): Game { - // #14 TODO: Uncomment this when the DB struct is ready. - // $item = $this->getCurrentDraft(); + $item = $this->getCurrentDraft(); // #14 Create if it doesn't exist yet. if (empty($item)) { $item = new Game(); $item->setStatus(Game::DRAFT); - // #14 TODO: Uncomment this when the DB struct is ready. -// $this->em->persist($item); -// $this->em->flush(); + $this->em->persist($item); + $this->em->flush(); } if (empty($item)) { @@ -88,13 +86,13 @@ public function mustFindCurrentDraft(): ?Game } /* - * #12 Shorthand to write to the database. + * #14 Shorthand to write to the database. */ -// public function save() -// { -// $this->em->flush(); -// $this->em->clear(); -// } + public function save() + { + $this->em->flush(); + $this->em->clear(); + } /* * #12 Mark the game as completed. diff --git a/symfony5/tests/GameUnitTest.php b/symfony5/tests/GameUnitTest.php new file mode 100644 index 0000000..99707da --- /dev/null +++ b/symfony5/tests/GameUnitTest.php @@ -0,0 +1,27 @@ +c = $kernel->getContainer(); + $this->gameRepo = $this->c->get('test.'.IGameRepo::class); + } + + public function testValid() + { + $this->assertNull($this->gameRepo->getCurrentDraft()); + } +}