WIP: Symfony 6 project remake #2
|
@ -20,6 +20,8 @@ services:
|
|||
$pointApiDelay: 5000
|
||||
$pointAppUserId: ''
|
||||
$pointApiClient: '@app.point.http_client'
|
||||
# Crawler API
|
||||
$crawlerToken: ''
|
||||
|
||||
# makes classes in src/ available to be used as services
|
||||
# this creates a service per class whose id is the fully-qualified class name
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace src\PointToolsBundle\Controller\Api;
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
@ -15,9 +16,6 @@ class AbstractApiController extends AbstractController
|
|||
], $code);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected function createErrorResponse(string $message, int $code = 400): Response
|
||||
{
|
||||
return $this->json([
|
|
@ -1,22 +1,19 @@
|
|||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace src\PointToolsBundle\Controller\Api;
|
||||
namespace App\Controller\Api;
|
||||
|
||||
use App\DTO\Api\PostsPage;
|
||||
use App\Factory\Blog\PostFactory;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use JMS\Serializer\SerializerInterface;
|
||||
use src\PointToolsBundle\DTO\Api\PostsPage;
|
||||
use src\PointToolsBundle\Service\Factory\Blogs\PostFactory;
|
||||
use Symfony\Component\HttpFoundation\{Request, Response};
|
||||
use src\PointToolsBundle\Controller\Api\AbstractApiController;
|
||||
|
||||
class CrawlerController extends AbstractApiController
|
||||
{
|
||||
/** @var string */
|
||||
private $crawlerToken;
|
||||
|
||||
public function __construct(string $crawlerToken)
|
||||
{
|
||||
$this->crawlerToken = $crawlerToken;
|
||||
public function __construct(
|
||||
private readonly string $crawlerToken,
|
||||
) {
|
||||
}
|
||||
|
||||
public function receiveAllPageAction(Request $request, SerializerInterface $serializer, PostFactory $postFactory, EntityManagerInterface $em): Response
|
||||
|
@ -24,7 +21,10 @@ class CrawlerController extends AbstractApiController
|
|||
$remoteToken = $request->request->get('token');
|
||||
|
||||
if (!$this->crawlerToken || ($this->crawlerToken !== $remoteToken)) {
|
||||
return $this->createErrorResponse('Token error. Please check it in crawler and API parameters.', Response::HTTP_FORBIDDEN);
|
||||
return $this->createErrorResponse(
|
||||
'Token error. Please check it in crawler and API parameters.',
|
||||
Response::HTTP_FORBIDDEN,
|
||||
);
|
||||
}
|
||||
|
||||
$json = $request->request->get('json');
|
Loading…
Reference in a new issue