Move points per match to season entity
dyb-tech.com/LaLiga-BackEnd/pipeline/head This commit looks good

This commit is contained in:
Daniel Guzman
2024-06-02 22:41:59 +02:00
parent 5ee51cf82b
commit 65b02bc11e
14 changed files with 181 additions and 158 deletions
+1 -54
View File
@@ -13,9 +13,6 @@ class LeagueDto
public string $city;
public string $logo;
public string $description;
public int $pointsPerWin;
public int $pointsPerDraw;
public int $pointsPerLoss;
public int $matchesBetweenTeams;
public array $blockedMatchDates;
public bool $active;
@@ -41,9 +38,6 @@ class LeagueDto
'city' => $this->city ?? null,
'logo' => $this->logo ?? null,
'description' => $this->description ?? null,
'pointsPerWin' => $this->pointsPerWin ?? null,
'pointsPerDraw' => $this->pointsPerDraw ?? null,
'pointsPerLoss' => $this->pointsPerLoss ?? null,
'matchesBetweenTeams' => $this->matchesBetweenTeams ?? [],
'blockedMatchDates' => $this->blockedMatchDates ?? [],
'active' => $this->active ?? null,
@@ -91,18 +85,6 @@ class LeagueDto
{
$this->description = $dataList['description'];
}
if (isset($dataList['pointsPerWin']))
{
$this->pointsPerWin = (int) $dataList['pointsPerWin'];
}
if (isset($dataList['pointsPerDraw']))
{
$this->pointsPerDraw = (int) $dataList['pointsPerDraw'];
}
if (isset($dataList['pointsPerLoss']))
{
$this->pointsPerLoss = (int) $dataList['pointsPerLoss'];
}
if (isset($dataList['matchesBetweenTeams']))
{
$this->matchesBetweenTeams = (int) $dataList['matchesBetweenTeams'];
@@ -152,18 +134,6 @@ class LeagueDto
{
$this->logo = $leagueObj->getLogo();
}
if ($leagueObj->getPointsPerWin() !== null)
{
$this->pointsPerWin = $leagueObj->getPointsPerWin();
}
if ($leagueObj->getPointsPerDraw() !== null)
{
$this->pointsPerDraw = $leagueObj->getPointsPerDraw();
}
if ($leagueObj->getPointsPerLoss() !== null)
{
$this->pointsPerLoss = $leagueObj->getPointsPerLoss();
}
if ($leagueObj->getMatchesBetweenTeams() !== null)
{
$this->matchesBetweenTeams = $leagueObj->getMatchesBetweenTeams();
@@ -204,30 +174,7 @@ class LeagueDto
{
$this->validationErrors[] = 'La localidad no puede estar vacía.';
}
if (empty($this->pointsPerWin))
{
$this->validationErrors[] = 'Los puntos por partido ganado no pueden estar vacíos.';
}
if (
isset($this->pointsPerDraw, $this->pointsPerWin, $this->pointsPerLoss) &&
(($this->pointsPerWin <= $this->pointsPerDraw) ||
($this->pointsPerWin <= $this->pointsPerLoss))
)
{
$this->validationErrors[] = 'Los puntos por partido ganado deben ser superiores a los puntos por empate y por perdida.';
}
if (isset($this->pointsPerDraw, $this->pointsPerWin) && ($this->pointsPerDraw > $this->pointsPerWin))
{
$this->validationErrors[] = 'Los puntos por empate deben ser inferiores a los puntos por partido ganado.';
}
if (isset($this->pointsPerDraw, $this->pointsPerLoss) && ($this->pointsPerDraw < $this->pointsPerLoss))
{
$this->validationErrors[] = 'Los puntos por empate deben ser superiores a los puntos por partido perdido.';
}
if (isset($this->pointsPerDraw, $this->pointsPerWin, $this->pointsPerLoss) && ($this->pointsPerWin + $this->pointsPerDraw + $this->pointsPerLoss > 20))
{
$this->validationErrors[] = 'La suma de los puntos por partidos ganados, perdidos y empatados no puede ser superior a 20.';
}
if (!empty($this->validationErrors))
{
throw new ValidationException($this->validationErrors);
+39
View File
@@ -12,6 +12,9 @@ class SeasonDto
public array $teamDtoList;
public array $facilityDtoList;
public int $leagueId;
public int $pointsPerWin;
public int $pointsPerLoss;
public int $pointsPerDraw;
public array $gameDtoList;
public array $seasonDataDtoList;
public bool $active;
@@ -59,6 +62,18 @@ class SeasonDto
$this->dateStart = $dateStart;
}
}
if (isset($dataList['pointsPerWin']))
{
$this->pointsPerWin = (int) $dataList['pointsPerWin'];
}
if (isset($dataList['pointsPerDraw']))
{
$this->pointsPerDraw = (int) $dataList['pointsPerDraw'];
}
if (isset($dataList['pointsPerLoss']))
{
$this->pointsPerLoss = (int) $dataList['pointsPerLoss'];
}
if (isset($dataList['active']))
{
$this->active = $dataList['active'];
@@ -118,6 +133,30 @@ class SeasonDto
*/
public function validate(): void
{
if (empty($this->pointsPerWin))
{
$this->validationErrors[] = 'Los puntos por partido ganado no pueden estar vacíos.';
}
if (
isset($this->pointsPerDraw, $this->pointsPerWin, $this->pointsPerLoss) &&
(($this->pointsPerWin <= $this->pointsPerDraw) ||
($this->pointsPerWin <= $this->pointsPerLoss))
)
{
$this->validationErrors[] = 'Los puntos por partido ganado deben ser superiores a los puntos por empate y por perdida.';
}
if (isset($this->pointsPerDraw, $this->pointsPerWin) && ($this->pointsPerDraw > $this->pointsPerWin))
{
$this->validationErrors[] = 'Los puntos por empate deben ser inferiores a los puntos por partido ganado.';
}
if (isset($this->pointsPerDraw, $this->pointsPerLoss) && ($this->pointsPerDraw < $this->pointsPerLoss))
{
$this->validationErrors[] = 'Los puntos por empate deben ser superiores a los puntos por partido perdido.';
}
if (isset($this->pointsPerDraw, $this->pointsPerWin, $this->pointsPerLoss) && ($this->pointsPerWin + $this->pointsPerDraw + $this->pointsPerLoss > 20))
{
$this->validationErrors[] = 'La suma de los puntos por partidos ganados, perdidos y empatados no puede ser superior a 20.';
}
if (!empty($this->validationErrors))
{
throw new ValidationException($this->validationErrors);
-45
View File
@@ -35,18 +35,9 @@ class League
#[ORM\Column(nullable: true)]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\Column(nullable: true)]
private ?int $pointsPerWin = null;
#[ORM\Column(nullable: true)]
private ?int $pointsPerDraw = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $city = null;
#[ORM\Column(nullable: true)]
private ?int $pointsPerLoss = null;
#[ORM\Column(nullable: true)]
private ?int $matchesBetweenTeams = null;
@@ -158,30 +149,6 @@ class League
$this->createdAt = new \DateTimeImmutable('now', $timezone);
}
public function getPointsPerWin(): ?int
{
return $this->pointsPerWin;
}
public function setPointsPerWin(?int $pointsPerWin): static
{
$this->pointsPerWin = $pointsPerWin;
return $this;
}
public function getPointsPerDraw(): ?int
{
return $this->pointsPerDraw;
}
public function setPointsPerDraw(?int $pointsPerDraw): static
{
$this->pointsPerDraw = $pointsPerDraw;
return $this;
}
public function getCity(): ?string
{
return $this->city;
@@ -194,18 +161,6 @@ class League
return $this;
}
public function getPointsPerLoss(): ?int
{
return $this->pointsPerLoss;
}
public function setPointsPerLoss(?int $pointsPerLoss): static
{
$this->pointsPerLoss = $pointsPerLoss;
return $this;
}
public function getMatchesBetweenTeams(): ?int
{
return $this->matchesBetweenTeams;
+45
View File
@@ -44,6 +44,15 @@ class Season
#[ORM\OneToMany(mappedBy: 'season', targetEntity: File::class)]
private Collection $files;
#[ORM\Column(nullable: true)]
private ?int $pointsPerWin = null;
#[ORM\Column(nullable: true)]
private ?int $pointsPerDraw = null;
#[ORM\Column(nullable: true)]
private ?int $pointsPerLoss = null;
public function __construct()
{
$this->teams = new ArrayCollection();
@@ -242,4 +251,40 @@ class Season
return $this;
}
public function getPointsPerWin(): ?int
{
return $this->pointsPerWin;
}
public function setPointsPerWin(?int $pointsPerWin): static
{
$this->pointsPerWin = $pointsPerWin;
return $this;
}
public function getPointsPerDraw(): ?int
{
return $this->pointsPerDraw;
}
public function setPointsPerDraw(?int $pointsPerDraw): static
{
$this->pointsPerDraw = $pointsPerDraw;
return $this;
}
public function getPointsPerLoss(): ?int
{
return $this->pointsPerLoss;
}
public function setPointsPerLoss(?int $pointsPerLoss): static
{
$this->pointsPerLoss = $pointsPerLoss;
return $this;
}
}
+22 -25
View File
@@ -28,58 +28,55 @@ class AuthorizeRequest
throw new HttpException(Response::HTTP_FORBIDDEN, "Unauthorized.");
}
$customRole = $this->customRoleRepository->findBy([
'name' => $leagueId . Role::LEAGUE_PRESIDENT->value,
'userEntity' => $userEntity
'name' => Role::LEAGUE_PRESIDENT->value,
'user' => $userEntity,
'entityId' => $leagueId
]);
if (is_null($customRole))
{
throw new HttpException(Response::HTTP_FORBIDDEN, "Usuario no tiene permiso para editar la liga.");
throw new HttpException(Response::HTTP_FORBIDDEN, "Forbidden");
}
}
public function teamCaptainRequest(int $leagueId, $teamId): User
{
$userEntity = $this->security->getUser();
if (!$userEntity instanceof User)
$requestingUserEntity = $this->security->getUser();
if (!$requestingUserEntity instanceof User)
{
throw new HttpException(Response::HTTP_FORBIDDEN, "Unauthorized");
}
$captainCustomRole = $this->customRoleRepository->findBy([
'name' => $teamId . Role::TEAM_CAPTAIN->value,
'name' => Role::TEAM_CAPTAIN->value,
'entityId' => $teamId
]);
if (!is_null($captainCustomRole))
{
throw new HttpException(Response::HTTP_FORBIDDEN, "Equipo con id: $teamId ya tiene capitan");
}
$leagueMemberRole = $this->customRoleRepository->findBy([
'name' => $leagueId . Role::LEAGUE_MEMBER->value,
'user' => $userEntity
'name' => Role::LEAGUE_MEMBER->value,
'user' => $requestingUserEntity,
'entityId' => $leagueId
]);
if (is_null($leagueMemberRole))
{
throw new HttpException(Response::HTTP_FORBIDDEN, "Usuario no es miembro de la liga");
throw new HttpException(Response::HTTP_FORBIDDEN, "Debes ser miembro de la liga antes de solicitar ser capitan.");
}
return $userEntity;
return $requestingUserEntity;
}
public function isLeaguePresident(int $leagueId, User $leagueAdmin): bool
{
$adminRoles = $leagueAdmin->getCustomRoles();
if (!$adminRoles->isEmpty())
$customRole = $this->customRoleRepository->findBy([
'name' => Role::LEAGUE_PRESIDENT->value,
'entityId' => $leagueId,
'user' => $leagueAdmin
]
);
if (is_null($customRole))
{
foreach ($adminRoles as $adminRoleEntity)
{
$explodedRole = explode('_', $adminRoleEntity->getName());
if (
strtolower($explodedRole[1]) == 'league' &&
strtolower($explodedRole[2]) == 'president' &&
$explodedRole[0] == $leagueId
)
{
return true;
}
}
throw new HttpException(Response::HTTP_FORBIDDEN,'Forbidden.');
}
throw new HttpException(Response::HTTP_NOT_FOUND,'Forbidden.');
return true;
}
}
+1 -1
View File
@@ -46,7 +46,7 @@ class LeagueFactory
{
$leagueEntity->setCity($leagueDto->city);
}
if (!empty($leagueDto->isPublic))
if (isset($leagueDto->isPublic))
{
$leagueEntity->setIsPublic($leagueDto->isPublic);
}
+12
View File
@@ -15,6 +15,18 @@ class SeasonFactory
{
$seasonEntity->setDateStart($seasonDto->dateStart);
}
if (isset($seasonDto->pointsPerWin))
{
$seasonEntity->setPointsPerWin($seasonDto->pointsPerWin);
}
if (isset($seasonDto->pointsPerDraw))
{
$seasonEntity->setPointsPerDraw($seasonDto->pointsPerDraw);
}
if (isset($seasonDto->pointsPerLoss))
{
$seasonEntity->setPointsPerLoss($seasonDto->pointsPerLoss);
}
return $seasonEntity;
}
}