feat: use DB awards instead of live Wikidata calls for hint generation

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
thibaud-leclere
2026-04-01 14:29:36 +02:00
parent 0fd0b85b8f
commit fb13a8819d
2 changed files with 77 additions and 11 deletions

View File

@@ -11,7 +11,7 @@ use App\Entity\User;
use App\Repository\ActorRepository;
use App\Repository\MovieRepository;
use App\Repository\MovieRoleRepository;
use App\Gateway\WikidataGateway;
use App\Repository\AwardRepository;
use Doctrine\ORM\EntityManagerInterface;
class GameGridGenerator
@@ -20,7 +20,7 @@ class GameGridGenerator
private readonly ActorRepository $actorRepository,
private readonly MovieRoleRepository $movieRoleRepository,
private readonly MovieRepository $movieRepository,
private readonly WikidataGateway $wikidataGateway,
private readonly AwardRepository $awardRepository,
private readonly EntityManagerInterface $em,
) {}
@@ -173,16 +173,11 @@ class GameGridGenerator
return ['type' => 'character', 'data' => (string) $role->getId()];
case 'award':
try {
$awards = $this->wikidataGateway->getAwards($rowActor);
} catch (\Throwable) {
$award = $this->awardRepository->findOneRandomByActor($rowActor->getId());
if ($award === null) {
return null;
}
if (!empty($awards)) {
$award = $awards[array_rand($awards)];
return ['type' => 'award', 'data' => $award['name'] . ' (' . $award['year'] . ')'];
}
return null;
return ['type' => 'award', 'data' => (string) $award->getId()];
}
return null;
@@ -200,8 +195,23 @@ class GameGridGenerator
return match ($type) {
'film' => $this->movieRepository->find((int) $data)?->getTitle(),
'character' => $this->movieRoleRepository->find((int) $data)?->getCharacter(),
'award' => $data,
'award' => $this->resolveAwardHintText((int) $data),
default => null,
};
}
private function resolveAwardHintText(int $awardId): ?string
{
$award = $this->awardRepository->find($awardId);
if ($award === null) {
return null;
}
$text = $award->getName();
if ($award->getYear() !== null) {
$text .= ' (' . $award->getYear() . ')';
}
return $text;
}
}