src/UI/RestBundle/Controller/Whater/PublicWhaterNfcController.php line 18

Open in your IDE?
  1. <?php
  2. namespace Whater\UI\RestBundle\Controller\Whater;
  3. use Whater\UI\RestBundle\Controller\AbstractBusController;
  4. use FOS\RestBundle\Controller\Annotations\View;
  5. use FOS\RestBundle\Controller\Annotations\Route;
  6. use Swagger\Annotations as SWG;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Whater\Application\UseCase\Whater\CommandRequest\RegisterWhaterNfcRequestCommand;
  9. /**
  10. * Class PublicWhaterNfcController
  11. *
  12. * @package Whater\UI\RestBundle\Controller\Whater
  13. * @Route("public")
  14. */
  15. class PublicWhaterNfcController extends AbstractBusController
  16. {
  17. /**
  18. * @Route("/whater-nfc/register-request", methods={"POST"})
  19. * @SWG\Post( tags={"Closca"}, consumes={"application/x-www-form-urlencoded"}, produces={"application/json"})
  20. * @SWG\Parameter(name="UID", in="formData", type="string", default="04:99:0D:62:7B:1D:94")
  21. * @SWG\Parameter(name="whaterpoint_id", in="formData", type="string", default="49d1e97b-88eb-449c-ae49-8062067bf0ec")
  22. * @SWG\Response(response=200, description="Returns ...") *
  23. * @View(statusCode=202, serializerGroups={"ApiRestWhaterNfcRequest"})
  24. *
  25. * @return \Symfony\Component\Form\FormInterface|\FOS\RestBundle\View\View
  26. */
  27. public function postWhaterNFCRequestByCloscaAction(Request $request)
  28. {
  29. try {
  30. // $ctrlInfo = $request->request->get('CTRLINFO');
  31. // $osn = $request->request->get('OSN');
  32. // $sn = $request->request->get('SN');
  33. $nfcId = $request->request->get('UID'); #04:99:0D:62:7B:1D:94
  34. // $online = $request->request->get('online');
  35. $whaterpointId = $request->request->get('whaterpoint_id');
  36. if (empty($whaterpointId)) {
  37. throw new \Exception('whaterpoint_id parameter required');
  38. }
  39. if (empty($nfcId)) {
  40. throw new \Exception('UID parameter required');
  41. }
  42. $isCloscaEndPoint = true;
  43. $registerWhaterNfcRequestCommand = new RegisterWhaterNfcRequestCommand(
  44. $whaterpointId,
  45. $nfcId,
  46. $isCloscaEndPoint
  47. );
  48. return $this->handle($registerWhaterNfcRequestCommand);
  49. } catch (\Exception $e) {
  50. return $this->sendBadRequestResponse();
  51. }
  52. }
  53. /**
  54. * @Route("/whater-nfc/register-whater-request", methods={"POST"})
  55. * @SWG\Post( tags={"Closca"}, consumes={"application/x-www-form-urlencoded"}, produces={"application/json"})
  56. * @SWG\Parameter(name="UID", in="formData", type="string", default="04:99:0D:62:7B:1D:94")
  57. * @SWG\Parameter(name="whaterpoint_id", in="formData", type="string", default="49d1e97b-88eb-449c-ae49-8062067bf0ec")
  58. * @SWG\Response(response=200, description="Returns ...") *
  59. * @View(statusCode=202, serializerGroups={"ApiRestWhaterNfcRequest"})
  60. *
  61. * @return \Symfony\Component\Form\FormInterface|\FOS\RestBundle\View\View
  62. */
  63. public function postWhaterNFCRequestByWhatertAction(Request $request)
  64. {
  65. try {
  66. // $ctrlInfo = $request->request->get('CTRLINFO');
  67. // $osn = $request->request->get('OSN');
  68. // $sn = $request->request->get('SN');
  69. $nfcId = $request->request->get('UID'); #04:99:0D:62:7B:1D:94
  70. // $online = $request->request->get('online');
  71. $whaterpointId = $request->request->get('whaterpoint_id');
  72. if (empty($whaterpointId)) {
  73. throw new \Exception('whaterpoint_id parameter required');
  74. }
  75. if (empty($nfcId)) {
  76. throw new \Exception('UID parameter required');
  77. }
  78. $isCloscaEndPoint = false;
  79. $registerWhaterNfcRequestCommand = new RegisterWhaterNfcRequestCommand(
  80. $whaterpointId,
  81. $nfcId,
  82. $isCloscaEndPoint
  83. );
  84. return $this->handle($registerWhaterNfcRequestCommand);
  85. } catch (\Exception $e) {
  86. return $this->sendBadRequestResponse();
  87. }
  88. }
  89. }