final fix for appellation selector: define metier when appellation already exists

This commit is contained in:
Julie Lenaerts 2024-05-23 14:05:14 +02:00
parent 405aad7333
commit 436ef33dbc
2 changed files with 32 additions and 32 deletions

View File

@ -12,11 +12,7 @@ declare(strict_types=1);
namespace Chill\FranceTravailApiBundle\ApiHelper;
use GuzzleHttp\Client;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Utils;
use Psr\Log\LoggerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
/**
@ -68,13 +64,15 @@ class PartenaireRomeAppellation
try {
$response = $this->httpClient->request(
'GET', self::BASE . 'appellation/requete', [
'GET',
self::BASE.'appellation/requete',
[
'headers' => [
'Authorization' => 'Bearer '.$bearer,
'Accept' => 'application/json',
],
'query' => [
'q' => $search
'q' => $search,
],
]
);
@ -90,7 +88,7 @@ class PartenaireRomeAppellation
$bearer = $this->getBearer();
try {
$response = $this->httpClient->request('GET', sprintf(self::BASE . 'appellation/%s', $code), [
$response = $this->httpClient->request('GET', sprintf(self::BASE.'appellation/%s', $code), [
'headers' => [
'Authorization' => 'Bearer '.$bearer,
'Accept' => 'application/json',

View File

@ -11,7 +11,6 @@ declare(strict_types=1);
namespace Chill\JobBundle\Form\ChoiceLoader;
use App\App;
use Chill\FranceTravailApiBundle\ApiHelper\PartenaireRomeAppellation;
use Symfony\Component\Form\ChoiceList\Loader\ChoiceLoaderInterface;
use Symfony\Component\Form\ChoiceList\ChoiceListInterface;
@ -87,6 +86,10 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
$code = \substr($v, \strlen('original-'));
$appellation = $this->appellationRepository->findOneBy(['code' => $code]);
if ($appellation) {
$metier = $appellation->getMetier();
}
if (null === $appellation) {
if (array_key_exists($v, $this->toBeCreated)) {
[$appellation, $metier] = $this->toBeCreated[$v];
@ -101,8 +104,7 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
if (null === $appellation && '' !== $code) {
$def = $this->apiAppellation->getAppellation($code);
$metier = $metier
?? $this->em->getRepository(Metier::class)
$metier ??= $this->em->getRepository(Metier::class)
->findOneBy(['code' => $def['metier']['code']])
?? (new Metier())
->setCode($def['metier']['code'])
@ -119,7 +121,7 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
$errorsAppellation = $this->validator->validate($appellation);
$errorsMetier = $this->validator->validate($metier);
if ($errorsAppellation->count() === 0 && $errorsMetier->count() === 0) {
if (0 === $errorsAppellation->count() && 0 === $errorsMetier->count()) {
$this->toBeCreated[$v] = [$appellation, $metier];
$this->em->persist($appellation);
}