AbstractApiController and CrawlerController draft added.
This commit is contained in:
parent
5ccefa630f
commit
7dfb520161
|
@ -0,0 +1,31 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Skobkin\Bundle\PointToolsBundle\Controller\Api;
|
||||||
|
|
||||||
|
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
|
||||||
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
|
|
||||||
|
class AbstractApiController extends Controller
|
||||||
|
{
|
||||||
|
protected function createSuccessResponse($data, $code = 200)
|
||||||
|
{
|
||||||
|
return new JsonResponse([
|
||||||
|
'status' => 'success',
|
||||||
|
'data' => $data,
|
||||||
|
], $code);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
protected function createErrorResponse($message, $code = 400)
|
||||||
|
{
|
||||||
|
return new JsonResponse([
|
||||||
|
'status' => 'fail',
|
||||||
|
'error' => [
|
||||||
|
'code' => (int) $code,
|
||||||
|
'message' => $message
|
||||||
|
]
|
||||||
|
], $code);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,22 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Skobkin\Bundle\PointToolsBundle\Controller\Api;
|
||||||
|
|
||||||
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
|
|
||||||
|
class CrawlerController extends AbstractApiController
|
||||||
|
{
|
||||||
|
public function receiveAllPageAction(Request $request)
|
||||||
|
{
|
||||||
|
$token = $request->request->get('token');
|
||||||
|
$json = $request->request->get('json');
|
||||||
|
|
||||||
|
$serializer = $this->get('serializer');
|
||||||
|
|
||||||
|
$data = $serializer->deserialize($json, 'Skobkin\Bundle\PointToolsBundle\DTO\Api\Crawler\PostsPage', 'json', ['groups' => ['import_post_page']]);
|
||||||
|
|
||||||
|
return $this->createSuccessResponse([
|
||||||
|
'continue' => true,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue