|
@@ -9,6 +9,7 @@ use App\ApiResources\OnlineRegistration\RegistrationAvailability;
|
|
|
use App\Entity\Access\Access;
|
|
use App\Entity\Access\Access;
|
|
|
use App\Service\ApiLegacy\ApiLegacyRequestService;
|
|
use App\Service\ApiLegacy\ApiLegacyRequestService;
|
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
|
|
+use Symfony\Component\HttpFoundation\Response;
|
|
|
|
|
|
|
|
class RegistrationAvailabilityProvider implements ProviderInterface
|
|
class RegistrationAvailabilityProvider implements ProviderInterface
|
|
|
{
|
|
{
|
|
@@ -25,13 +26,13 @@ class RegistrationAvailabilityProvider implements ProviderInterface
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?RegistrationAvailability
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): ?RegistrationAvailability
|
|
|
{
|
|
{
|
|
|
if ($operation instanceof GetCollection) {
|
|
if ($operation instanceof GetCollection) {
|
|
|
- throw new \RuntimeException('not supported', 500);
|
|
|
|
|
|
|
+ throw new \RuntimeException('not supported', Response::HTTP_INTERNAL_SERVER_ERROR);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/** @var Access $currentAccess */
|
|
/** @var Access $currentAccess */
|
|
|
$currentAccess = $this->security->getUser();
|
|
$currentAccess = $this->security->getUser();
|
|
|
if ($uriVariables['accessId'] !== $currentAccess->getId()) {
|
|
if ($uriVariables['accessId'] !== $currentAccess->getId()) {
|
|
|
- throw new \RuntimeException('forbidden', 503);
|
|
|
|
|
|
|
+ throw new \RuntimeException('forbidden', Response::HTTP_SERVICE_UNAVAILABLE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$response = $this->apiLegacyRequestService->get('/api/online_registration/access_verification');
|
|
$response = $this->apiLegacyRequestService->get('/api/online_registration/access_verification');
|
|
@@ -40,8 +41,8 @@ class RegistrationAvailabilityProvider implements ProviderInterface
|
|
|
|
|
|
|
|
$availability = new RegistrationAvailability();
|
|
$availability = new RegistrationAvailability();
|
|
|
$availability->setAccessId($currentAccess->getId());
|
|
$availability->setAccessId($currentAccess->getId());
|
|
|
- $availability->setAvailable($response->getStatusCode() === 200);
|
|
|
|
|
- $availability->setMessage($content['message']);
|
|
|
|
|
|
|
+ $availability->setAvailable($response->getStatusCode() === Response::HTTP_OK && !array_key_exists('error', $content));
|
|
|
|
|
+ $availability->setMessage(array_key_exists('message', $content) ? $content['message'] : null);
|
|
|
|
|
|
|
|
return $availability;
|
|
return $availability;
|
|
|
}
|
|
}
|