refs #658. OgBoot Webhook

feature/integration-ogboot
Manuel Aranda Rosales 2024-09-04 10:14:52 +02:00
parent 68b460935f
commit ebd3d7e539
3 changed files with 103 additions and 1 deletions

View File

@ -29,6 +29,7 @@ security:
- { path: ^/$, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI
- { path: ^/docs, roles: PUBLIC_ACCESS } # Allows accessing the Swagger UI docs
- { path: ^/auth/login, roles: PUBLIC_ACCESS }
- { path: ^/og-lives/install/webhook, roles: PUBLIC_ACCESS }
- { path: ^/auth/refresh, roles: PUBLIC_ACCESS }
- { path: ^/, roles: IS_AUTHENTICATED_FULLY }

View File

@ -0,0 +1,36 @@
<?php
namespace App\Controller\OgBoot\OgLive\Webhook;
use App\Controller\OgBoot\AbstractOgBootController;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Attribute\AsController;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Validator\Exception\ValidatorException;
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\RedirectionExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\ServerExceptionInterface;
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
use Symfony\Contracts\HttpClient\HttpClientInterface;
#[AsController]
class InstallOgLiveResponseAction extends AbstractController
{
public function __construct(
protected readonly EntityManagerInterface $entityManager
)
{
}
#[Route('/og-lives/install/webhook', name: 'install_webhook', methods: ['POST'])]
public function installWebhook(Request $request): JsonResponse
{
$data = json_decode($request->getContent(), true);
return new JsonResponse(data: ['hola caracola'], status: Response::HTTP_OK);
}
}

View File

@ -20,7 +20,8 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface
$this->addRefreshToken($openApi);
$this->addSearchEndpoint($openApi);
$this->addStatusEndpoint($openApi); // Agregar el nuevo endpoint
$this->addStatusEndpoint($openApi);
$this->addInstallOgLiveWebhookEndpoint($openApi); // Añadir aquí
return $openApi;
}
@ -175,4 +176,68 @@ final readonly class OpenApiFactory implements OpenApiFactoryInterface
->withSummary('Get service status')
));
}
private function addInstallOgLiveWebhookEndpoint(OpenApi $openApi): void
{
$openApi
->getPaths()
->addPath('/og-lives/install/webhook', (new Model\PathItem())->withPost(
(new Model\Operation('postInstallOgLiveWebhook'))
->withTags(['OgLive'])
->withResponses([
Response::HTTP_OK => [
'description' => 'Webhook installation successful',
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'message' => [
'type' => 'string',
'example' => 'Webhook installed successfully',
],
],
],
],
],
],
Response::HTTP_BAD_REQUEST => [
'description' => 'Invalid request data',
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'error' => [
'type' => 'string',
'example' => 'Invalid input data',
],
],
],
],
],
],
])
->withSummary('Install a webhook for OgLive')
->withRequestBody(
(new Model\RequestBody())
->withDescription('Data required for installing the webhook')
->withContent(new \ArrayObject([
'application/json' => new Model\MediaType(new \ArrayObject([
'type' => 'object',
'properties' => [
'da' => [
'type' => 'string',
'description' => 'The URL to set for the webhook',
'example' => 'https://example.com/webhook',
],
],
'required' => ['url'],
]))
]))
->withRequired(true)
)
));
}
}