mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
fix rome appellation selector and admin
This commit is contained in:
parent
a5c2576124
commit
405aad7333
@ -17,6 +17,7 @@ use GuzzleHttp\Psr7\Request;
|
||||
use GuzzleHttp\Utils;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
|
||||
|
||||
/**
|
||||
* Queries for ROME partenaires api.
|
||||
@ -39,9 +40,12 @@ class PartenaireRomeAppellation
|
||||
*/
|
||||
protected $logger;
|
||||
|
||||
private const BASE = 'https://api.pole-emploi.io/partenaire/rome-metiers/v1/metiers/';
|
||||
|
||||
public function __construct(
|
||||
ApiWrapper $wrapper,
|
||||
LoggerInterface $logger
|
||||
LoggerInterface $logger,
|
||||
private \Symfony\Contracts\HttpClient\HttpClientInterface $httpClient,
|
||||
) {
|
||||
$this->wrapper = $wrapper;
|
||||
$this->logger = $logger;
|
||||
@ -58,10 +62,7 @@ class PartenaireRomeAppellation
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $search
|
||||
*/
|
||||
public function getListeAppellation($search)
|
||||
public function getListeAppellation(string $search): array
|
||||
{
|
||||
$bearer = $this->getBearer();
|
||||
|
||||
@ -84,27 +85,24 @@ class PartenaireRomeAppellation
|
||||
}
|
||||
}
|
||||
|
||||
public function getAppellation($code)
|
||||
public function getAppellation(string $code): array
|
||||
{
|
||||
$bearer = $this->getBearer();
|
||||
|
||||
$request = new Request('GET', sprintf('appellation/%s', $code));
|
||||
$parameters = [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$bearer,
|
||||
],
|
||||
'query' => [
|
||||
'champs' => 'code,libelle,metier(code,libelle)',
|
||||
],
|
||||
];
|
||||
try {
|
||||
$response = $this->httpClient->request('GET', sprintf(self::BASE . 'appellation/%s', $code), [
|
||||
'headers' => [
|
||||
'Authorization' => 'Bearer '.$bearer,
|
||||
'Accept' => 'application/json',
|
||||
],
|
||||
'query' => [
|
||||
'champs' => 'code,libelle,metier(code,libelle)',
|
||||
],
|
||||
]);
|
||||
|
||||
$response = $this->handleRequest(
|
||||
$request,
|
||||
$parameters,
|
||||
$this->client,
|
||||
$this->logger
|
||||
);
|
||||
|
||||
return Utils::jsonDecode((string) $response->getBody());
|
||||
return $response->toArray();
|
||||
} catch (HttpExceptionInterface $exception) {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -41,8 +41,8 @@ class RomeController extends AbstractController
|
||||
$results = [];
|
||||
|
||||
foreach ($appellations as $appellation) {
|
||||
$appellation->id = 'original-'.$appellation->code;
|
||||
$appellation->text = $appellation->libelle;
|
||||
$appellation['id'] = 'original-'.$appellation['code'];
|
||||
$appellation['text'] = $appellation['libelle'];
|
||||
$results[] = $appellation;
|
||||
}
|
||||
|
||||
|
@ -1,12 +1,14 @@
|
||||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
Chill\FranceTravailApiBundle\ApiHelper\ApiWrapper:
|
||||
$clientId: '%env(FRANCE_TRAVAIL_CLIENT_ID)%'
|
||||
$clientSecret: '%env(FRANCE_TRAVAIL_CLIENT_SECRET)%'
|
||||
$redis: '@Chill\MainBundle\Redis\ChillRedis'
|
||||
|
||||
Chill\FranceTravailApiBundle\ApiHelper\PartenaireRomeAppellation:
|
||||
$wrapper: '@Chill\FranceTravailApiBundle\ApiHelper\ApiWrapper'
|
||||
$logger: '@Psr\Log\LoggerInterface'
|
||||
Chill\FranceTravailApiBundle\ApiHelper\PartenaireRomeAppellation: ~
|
||||
|
||||
Chill\FranceTravailApiBundle\Controller\RomeController:
|
||||
autowire: true
|
||||
|
@ -36,7 +36,7 @@ class Metier
|
||||
* @var \Doctrine\Common\Collections\Collection<int, \Chill\JobBundle\Entity\Rome\Appellation>
|
||||
*/
|
||||
#[ORM\OneToMany(targetEntity: Appellation::class, mappedBy: 'metier')]
|
||||
private readonly \Doctrine\Common\Collections\Collection $appellations;
|
||||
private \Doctrine\Common\Collections\Collection $appellations;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
|
@ -11,6 +11,7 @@ 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;
|
||||
@ -50,6 +51,11 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
|
||||
*/
|
||||
protected $validator;
|
||||
|
||||
/**
|
||||
* @var array<string, array{0: Appellation, 1: Metier}>
|
||||
*/
|
||||
private $toBeCreated = [];
|
||||
|
||||
public function __construct(
|
||||
EntityManagerInterface $em,
|
||||
PartenaireRomeAppellation $apiAppellation,
|
||||
@ -80,33 +86,41 @@ class RomeAppellationChoiceLoader implements ChoiceLoaderInterface
|
||||
if (str_starts_with($v, 'original-')) {
|
||||
$code = \substr($v, \strlen('original-'));
|
||||
$appellation = $this->appellationRepository->findOneBy(['code' => $code]);
|
||||
|
||||
if (null === $appellation) {
|
||||
if (array_key_exists($v, $this->toBeCreated)) {
|
||||
[$appellation, $metier] = $this->toBeCreated[$v];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$id = $v;
|
||||
$appellation = $this->appellationRepository->find($id);
|
||||
$metier = $appellation->getMetier();
|
||||
}
|
||||
|
||||
if (null === $appellation && '' !== $code) {
|
||||
$def = $this->apiAppellation->getAppellation($code);
|
||||
$metier = $this->em->getRepository(Metier::class)
|
||||
->findOneBy(['code' => $def->metier->code])
|
||||
;
|
||||
|
||||
if (null === $metier) {
|
||||
$metier = (new Metier())
|
||||
->setCode($def->metier->code)
|
||||
->setLibelle($def->metier->libelle)
|
||||
;
|
||||
}
|
||||
$metier = $metier
|
||||
?? $this->em->getRepository(Metier::class)
|
||||
->findOneBy(['code' => $def['metier']['code']])
|
||||
?? (new Metier())
|
||||
->setCode($def['metier']['code'])
|
||||
->setLibelle($def['metier']['libelle']);
|
||||
|
||||
$appellation = new Appellation();
|
||||
|
||||
$appellation
|
||||
->setCode($def->code)
|
||||
->setLibelle($def->libelle)
|
||||
->setCode($def['code'])
|
||||
->setLibelle($def['libelle'])
|
||||
->setMetier($metier)
|
||||
;
|
||||
|
||||
if ([] === $this->validator->validate($appellation) && [] === $this->validator->validate($metier)) {
|
||||
$errorsAppellation = $this->validator->validate($appellation);
|
||||
$errorsMetier = $this->validator->validate($metier);
|
||||
|
||||
if ($errorsAppellation->count() === 0 && $errorsMetier->count() === 0) {
|
||||
$this->toBeCreated[$v] = [$appellation, $metier];
|
||||
$this->em->persist($appellation);
|
||||
}
|
||||
}
|
||||
|
@ -151,7 +151,7 @@ final class PermissionsGroupController extends AbstractController
|
||||
/**
|
||||
* remove an association between permissionsGroup and roleScope.
|
||||
*/
|
||||
#[\Symfony\Component\Routing\Annotation\Route(path: '/{_locale}/admin/permissionsgroup/{pgid}/delete_link_role_scope/{rsid}', name: 'admin_permissionsgroup_delete_role_scope', methods: ['DELETE'])]
|
||||
#[\Symfony\Component\Routing\Annotation\Route(path: '/{_locale}/admin/permissionsgroup/{pgid}/delete_link_role_scope/{rsid}', name: 'admin_permissionsgroup_delete_role_scope', methods: ['POST'])]
|
||||
public function deleteLinkRoleScopeAction(int $pgid, int $rsid): Response
|
||||
{
|
||||
$permissionsGroup = $this->permissionsGroupRepository->find($pgid);
|
||||
|
Loading…
x
Reference in New Issue
Block a user