2016-03-22 17:45:05 +00:00
|
|
|
<?php
|
|
|
|
|
2023-03-11 16:27:07 +00:00
|
|
|
namespace src\PointToolsBundle\Controller\Api;
|
2016-03-22 17:45:05 +00:00
|
|
|
|
2017-11-05 02:03:26 +00:00
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
2017-01-09 00:33:29 +00:00
|
|
|
use Symfony\Component\HttpFoundation\Response;
|
2016-03-22 17:45:05 +00:00
|
|
|
|
2017-11-05 02:03:26 +00:00
|
|
|
class AbstractApiController extends AbstractController
|
2016-03-22 17:45:05 +00:00
|
|
|
{
|
2017-01-12 23:03:27 +00:00
|
|
|
protected function createSuccessResponse($data, int $code = 200): Response
|
2016-03-22 17:45:05 +00:00
|
|
|
{
|
2017-01-09 00:33:29 +00:00
|
|
|
return $this->json([
|
2016-03-22 17:45:05 +00:00
|
|
|
'status' => 'success',
|
|
|
|
'data' => $data,
|
|
|
|
], $code);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
2017-01-12 23:03:27 +00:00
|
|
|
protected function createErrorResponse(string $message, int $code = 400): Response
|
2016-03-22 17:45:05 +00:00
|
|
|
{
|
2017-01-09 00:33:29 +00:00
|
|
|
return $this->json([
|
2016-03-22 17:45:05 +00:00
|
|
|
'status' => 'fail',
|
|
|
|
'error' => [
|
2017-01-12 23:03:27 +00:00
|
|
|
'code' => $code,
|
2016-03-22 17:45:05 +00:00
|
|
|
'message' => $message
|
|
|
|
]
|
|
|
|
], $code);
|
|
|
|
}
|
|
|
|
}
|