From 0d48bcaa42ec0ee60b56df39228c91d538621471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Pimpa=CC=83o?= Date: Mon, 7 Oct 2024 12:22:43 +0100 Subject: [PATCH] feat: add rankings include to Team resource --- docs/05-entities.md | 11 +++++++ src/Entity/Ranking.php | 59 ++++++++++++++++++++++++++++++++++++++ src/Entity/Team.php | 9 ++++++ tests/Unit/RankingTest.php | 28 ++++++++++++++++++ 4 files changed, 107 insertions(+) create mode 100644 src/Entity/Ranking.php create mode 100644 tests/Unit/RankingTest.php diff --git a/docs/05-entities.md b/docs/05-entities.md index c081978..62dfe55 100644 --- a/docs/05-entities.md +++ b/docs/05-entities.md @@ -29,6 +29,7 @@ - [Player](#player) - [PlayerStatistic](#playerstatistic) - [PlayerStatisticDetail](#playerstatisticdetail) + - [Ranking](#ranking) - [Referee](#referee) - [RefereeStatistic](#refereestatistic) - [RefereeStatisticDetail](#refereestatisticdetail) @@ -496,6 +497,15 @@ - `getValue()`: `array` - `getType()`: [`?Type`](#type) (`type` include is required) +### Ranking + +- `getId()`: `?int` +- `getParticipantId()`: `?int` +- `getSportId()`: `?int` +- `getPosition()`: `?int` +- `getPoints()`: `?int` +- `getType()`: `?string` + ### Referee - `getId()`: `int` @@ -779,6 +789,7 @@ - `getSocials()`: [`?Social[]`](#social) (`scoails` include is required) - `getCoaches()`: [`?TeamCoach[]`](#teamcoach) (`coaches` include is required) - `getStatistics()`: [`?TeamStatistic[]`](#teamstatistic) (`statistics` include is required) +- `getRankings()`: [`?Ranking[]`](#ranking) (`rankings` include is required) ### TeamCoach diff --git a/src/Entity/Ranking.php b/src/Entity/Ranking.php new file mode 100644 index 0000000..6559e06 --- /dev/null +++ b/src/Entity/Ranking.php @@ -0,0 +1,59 @@ +id = $data['id'] ?? null; + $this->participantId = $data['participant_id'] ?? null; + $this->sportId = $data['sport_id'] ?? null; + $this->position = $data['position'] ?? null; + $this->points = $data['points'] ?? null; + $this->type = $data['type'] ?? null; + } + + public function getId(): ?int + { + return $this->id; + } + + public function getParticipantId(): ?int + { + return $this->participantId; + } + + public function getSportId(): ?int + { + return $this->sportId; + } + + public function getPosition(): ?int + { + return $this->position; + } + + public function getPoints(): ?int + { + return $this->points; + } + + public function getType(): ?string + { + return $this->type; + } +} \ No newline at end of file diff --git a/src/Entity/Team.php b/src/Entity/Team.php index 3cbee22..27e9436 100644 --- a/src/Entity/Team.php +++ b/src/Entity/Team.php @@ -74,6 +74,9 @@ class Team /** @var ?TeamStatistic[] */ private ?array $statistics; + /** @var ?Ranking[] */ + private ?array $rankings; + public function __construct(array $data, string $timezone) { $this->id = $data['id']; @@ -107,6 +110,7 @@ public function __construct(array $data, string $timezone) $this->socials = isset($data['socials']) ? $this->createEntityCollection(Social::class, $data['socials']) : null; $this->coaches = isset($data['coaches']) ? $this->createEntityCollection(TeamCoach::class, $data['coaches'], $timezone) : null; $this->statistics = isset($data['statistics']) ? $this->createEntityCollection(TeamStatistic::class, $data['statistics'], $timezone) : null; + $this->rankings = isset($data['rankings']) ? $this->createEntityCollection(Ranking::class, $data['rankings']) : null; } public function getId(): int @@ -243,4 +247,9 @@ public function getStatistics(): ?array { return $this->statistics; } + + public function getRankings(): ?array + { + return $this->rankings; + } } \ No newline at end of file diff --git a/tests/Unit/RankingTest.php b/tests/Unit/RankingTest.php new file mode 100644 index 0000000..4dea727 --- /dev/null +++ b/tests/Unit/RankingTest.php @@ -0,0 +1,28 @@ + 1, + 'participant_id' => 1, + 'sport_id' => 1, + 'position' => 1, + 'points' => 1, + 'type' => 'type' + ]); + + $this->assertSame(1, $entity->getId()); + $this->assertSame(1, $entity->getParticipantId()); + $this->assertSame(1, $entity->getSportId()); + $this->assertSame(1, $entity->getPosition()); + $this->assertSame(1, $entity->getPoints()); + $this->assertSame('type', $entity->getType()); + } +} \ No newline at end of file