<?php
namespace Whater\UI\RestBundle\Controller\Whater;
use Whater\UI\RestBundle\Controller\AbstractBusController;
use FOS\RestBundle\Controller\Annotations\View;
use FOS\RestBundle\Controller\Annotations\Route;
use Swagger\Annotations as SWG;
use Symfony\Component\HttpFoundation\Request;
use Whater\Application\UseCase\Whater\CommandRequest\RegisterWhaterNfcRequestCommand;
/**
* Class PublicWhaterNfcController
*
* @package Whater\UI\RestBundle\Controller\Whater
* @Route("public")
*/
class PublicWhaterNfcController extends AbstractBusController
{
/**
* @Route("/whater-nfc/register-request", methods={"POST"})
* @SWG\Post( tags={"Closca"}, consumes={"application/x-www-form-urlencoded"}, produces={"application/json"})
* @SWG\Parameter(name="UID", in="formData", type="string", default="04:99:0D:62:7B:1D:94")
* @SWG\Parameter(name="whaterpoint_id", in="formData", type="string", default="49d1e97b-88eb-449c-ae49-8062067bf0ec")
* @SWG\Response(response=200, description="Returns ...") *
* @View(statusCode=202, serializerGroups={"ApiRestWhaterNfcRequest"})
*
* @return \Symfony\Component\Form\FormInterface|\FOS\RestBundle\View\View
*/
public function postWhaterNFCRequestByCloscaAction(Request $request)
{
try {
// $ctrlInfo = $request->request->get('CTRLINFO');
// $osn = $request->request->get('OSN');
// $sn = $request->request->get('SN');
$nfcId = $request->request->get('UID'); #04:99:0D:62:7B:1D:94
// $online = $request->request->get('online');
$whaterpointId = $request->request->get('whaterpoint_id');
if (empty($whaterpointId)) {
throw new \Exception('whaterpoint_id parameter required');
}
if (empty($nfcId)) {
throw new \Exception('UID parameter required');
}
$isCloscaEndPoint = true;
$registerWhaterNfcRequestCommand = new RegisterWhaterNfcRequestCommand(
$whaterpointId,
$nfcId,
$isCloscaEndPoint
);
return $this->handle($registerWhaterNfcRequestCommand);
} catch (\Exception $e) {
return $this->sendBadRequestResponse();
}
}
/**
* @Route("/whater-nfc/register-whater-request", methods={"POST"})
* @SWG\Post( tags={"Closca"}, consumes={"application/x-www-form-urlencoded"}, produces={"application/json"})
* @SWG\Parameter(name="UID", in="formData", type="string", default="04:99:0D:62:7B:1D:94")
* @SWG\Parameter(name="whaterpoint_id", in="formData", type="string", default="49d1e97b-88eb-449c-ae49-8062067bf0ec")
* @SWG\Response(response=200, description="Returns ...") *
* @View(statusCode=202, serializerGroups={"ApiRestWhaterNfcRequest"})
*
* @return \Symfony\Component\Form\FormInterface|\FOS\RestBundle\View\View
*/
public function postWhaterNFCRequestByWhatertAction(Request $request)
{
try {
// $ctrlInfo = $request->request->get('CTRLINFO');
// $osn = $request->request->get('OSN');
// $sn = $request->request->get('SN');
$nfcId = $request->request->get('UID'); #04:99:0D:62:7B:1D:94
// $online = $request->request->get('online');
$whaterpointId = $request->request->get('whaterpoint_id');
if (empty($whaterpointId)) {
throw new \Exception('whaterpoint_id parameter required');
}
if (empty($nfcId)) {
throw new \Exception('UID parameter required');
}
$isCloscaEndPoint = false;
$registerWhaterNfcRequestCommand = new RegisterWhaterNfcRequestCommand(
$whaterpointId,
$nfcId,
$isCloscaEndPoint
);
return $this->handle($registerWhaterNfcRequestCommand);
} catch (\Exception $e) {
return $this->sendBadRequestResponse();
}
}
}