feat: add Award entity and repository

This commit is contained in:
thibaud-leclere
2026-04-01 14:23:23 +02:00
parent acc266739d
commit 859a5a1067
3 changed files with 124 additions and 0 deletions

View File

@@ -30,9 +30,14 @@ class Actor
#[ORM\Column(nullable: true)]
private ?int $tmdbId = null;
/** @var Collection<int, Award> */
#[ORM\OneToMany(targetEntity: Award::class, mappedBy: 'actor')]
private Collection $awards;
public function __construct()
{
$this->movieRoles = new ArrayCollection();
$this->awards = new ArrayCollection();
}
public function getId(): ?int
@@ -105,4 +110,10 @@ class Actor
return $this;
}
/** @return Collection<int, Award> */
public function getAwards(): Collection
{
return $this->awards;
}
}

84
src/Entity/Award.php Normal file
View File

@@ -0,0 +1,84 @@
<?php
declare(strict_types=1);
namespace App\Entity;
use App\Repository\AwardRepository;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: AwardRepository::class)]
class Award
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: AwardType::class, inversedBy: 'awards')]
#[ORM\JoinColumn(nullable: false)]
private AwardType $awardType;
#[ORM\ManyToOne(targetEntity: Actor::class, inversedBy: 'awards')]
#[ORM\JoinColumn(nullable: false)]
private Actor $actor;
#[ORM\Column(length: 255)]
private string $name;
#[ORM\Column(nullable: true)]
private ?int $year = null;
public function getId(): ?int
{
return $this->id;
}
public function getAwardType(): AwardType
{
return $this->awardType;
}
public function setAwardType(AwardType $awardType): static
{
$this->awardType = $awardType;
return $this;
}
public function getActor(): Actor
{
return $this->actor;
}
public function setActor(Actor $actor): static
{
$this->actor = $actor;
return $this;
}
public function getName(): string
{
return $this->name;
}
public function setName(string $name): static
{
$this->name = $name;
return $this;
}
public function getYear(): ?int
{
return $this->year;
}
public function setYear(?int $year): static
{
$this->year = $year;
return $this;
}
}

View File

@@ -0,0 +1,29 @@
<?php
declare(strict_types=1);
namespace App\Repository;
use App\Entity\Award;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/** @extends ServiceEntityRepository<Award> */
class AwardRepository extends ServiceEntityRepository
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, Award::class);
}
public function findOneRandomByActor(int $actorId): ?Award
{
return $this->createQueryBuilder('a')
->andWhere('a.actor = :actorId')
->setParameter('actorId', $actorId)
->orderBy('RANDOM()')
->setMaxResults(1)
->getQuery()
->getOneOrNullResult();
}
}