Skip to content

Commit

Permalink
user jms serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Feb 14, 2019
1 parent 50a46b9 commit aaf3a8b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
20 changes: 15 additions & 5 deletions src/Controller/v1/ReversionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use App\Service\DocumentRequestInterface;
use Greenter\Model\Voided\Reversion;
use JMS\Serializer\SerializerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -26,15 +28,21 @@ class ReversionController extends AbstractController
* @var DocumentRequestInterface
*/
private $document;
/**
* @var SerializerInterface
*/
private $serializer;

/**
* InvoiceController constructor.
* @param DocumentRequestInterface $document
* @param SerializerInterface $serializer
*/
public function __construct(DocumentRequestInterface $document)
public function __construct(DocumentRequestInterface $document, SerializerInterface $serializer)
{
$this->document = $document;
$this->document->setDocumentType(Reversion::class);
$this->serializer = $serializer;
}

/**
Expand Down Expand Up @@ -71,13 +79,13 @@ public function pdf(): Response
* @Route("/status", methods={"GET"})
*
* @param Request $request
* @return Response
* @return JsonResponse
*/
public function status(Request $request): Response
public function status(Request $request): JsonResponse
{
$ticket = $request->query->get('ticket');
if (empty($ticket)) {
return new Response('Ticket Requerido', 400);
return new JsonResponse(['message' => 'Ticket Requerido'], 400);
}
$see = $this->document->getSee();
$result = $see->getStatus($ticket);
Expand All @@ -86,6 +94,8 @@ public function status(Request $request): Response
$result->setCdrZip(base64_encode($result->getCdrZip()));
}

return $this->json($result);
$json = $this->serializer->serialize($result, 'json');

return new JsonResponse($json, 200, [], true);
}
}
20 changes: 15 additions & 5 deletions src/Controller/v1/SummaryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use App\Service\DocumentRequestInterface;
use Greenter\Model\Summary\Summary;
use JMS\Serializer\SerializerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -26,15 +28,21 @@ class SummaryController extends AbstractController
* @var DocumentRequestInterface
*/
private $document;
/**
* @var SerializerInterface
*/
private $serializer;

/**
* InvoiceController constructor.
* @param DocumentRequestInterface $document
* @param SerializerInterface $serializer
*/
public function __construct(DocumentRequestInterface $document)
public function __construct(DocumentRequestInterface $document, SerializerInterface $serializer)
{
$this->document = $document;
$this->document->setDocumentType(Summary::class);
$this->serializer = $serializer;
}

/**
Expand Down Expand Up @@ -71,13 +79,13 @@ public function pdf(): Response
* @Route("/status", methods={"GET"})
*
* @param Request $request
* @return Response
* @return JsonResponse
*/
public function status(Request $request): Response
public function status(Request $request): JsonResponse
{
$ticket = $request->query->get('ticket');
if (empty($ticket)) {
return new Response('Ticket Requerido', 400);
return new JsonResponse(['message' => 'Ticket Requerido'], 400);
}
$see = $this->document->getSee();
$result = $see->getStatus($ticket);
Expand All @@ -86,6 +94,8 @@ public function status(Request $request): Response
$result->setCdrZip(base64_encode($result->getCdrZip()));
}

return $this->json($result);
$json = $this->serializer->serialize($result, 'json');

return new JsonResponse($json, 200, [], true);
}
}
19 changes: 14 additions & 5 deletions src/Controller/v1/VoidedController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

use App\Service\DocumentRequestInterface;
use Greenter\Model\Voided\Voided;
use JMS\Serializer\SerializerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
Expand All @@ -26,15 +28,21 @@ class VoidedController extends AbstractController
* @var DocumentRequestInterface
*/
private $document;
/**
* @var SerializerInterface
*/
private $serializer;

/**
* InvoiceController constructor.
* @param DocumentRequestInterface $document
* @param SerializerInterface $serializer
*/
public function __construct(DocumentRequestInterface $document)
public function __construct(DocumentRequestInterface $document, SerializerInterface $serializer)
{
$this->document = $document;
$this->document->setDocumentType(Voided::class);
$this->serializer = $serializer;
}

/**
Expand Down Expand Up @@ -71,21 +79,22 @@ public function pdf(): Response
* @Route("/status", methods={"GET"})
*
* @param Request $request
* @return Response
* @return JsonResponse
*/
public function status(Request $request): Response
public function status(Request $request): JsonResponse
{
$ticket = $request->query->get('ticket');
if (empty($ticket)) {
return new Response('Ticket Requerido', 400);
return new JsonResponse(['message' => 'Ticket Requerido'], 400);
}
$see = $this->document->getSee();
$result = $see->getStatus($ticket);

if ($result->isSuccess()) {
$result->setCdrZip(base64_encode($result->getCdrZip()));
}
$json = $this->serializer->serialize($result, 'json');

return $this->json($result);
return new JsonResponse($json, 200, [], true);
}
}

0 comments on commit aaf3a8b

Please sign in to comment.