AbstractApiController and CrawlerController draft added.

This commit is contained in:
Alexey Skobkin 2016-03-22 20:45:05 +03:00
parent 5ccefa630f
commit 7dfb520161
2 changed files with 53 additions and 0 deletions

View file

@ -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);
}
}

View file

@ -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,
]);
}
}