<?php
namespace App\Api;
use App\Entity\Sms;
use App\Entity\Station;
use App\Entity\WayBill;
use Doctrine\Persistence\ManagerRegistry;
use Doctrine\Persistence\ObjectManager;
use FOS\RestBundle\Controller\AbstractFOSRestController;
use FOS\RestBundle\Controller\Annotations as Rest;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class SmsController extends AbstractFOSRestController {
private ObjectManager $em;
public function __construct(ManagerRegistry $registry)
{
$this->em = $registry->getManager();
}
// {
// phoneNumber: '+254721459276',
// failureReason: 'UserInBlackList',
// retryCount: '0',
// id: 'ATXid_05fa295f25664bce10c2813df28ddcc4',
// status: 'Failed',
// networkCode: '63902'
// }
// {
// "phoneNumber":"+254721459276",
// "failureReason":"UserInBlackList",
// "retryCount":"0",
// "id":"ATXid_9dc512ca196b7f93002724bff2f0db97",
// "status":"Failed",
// "networkCode":"63902"
// }
/**
* @Rest\Get("/sms/failed/{stationId}", name="failed_sms")
*/
public function getFailedSms(Request $request, $stationId)
{
$failedDeliveryNotifications = $this->em->getRepository(WayBill::class)->findFailedSms($stationId);
// return $this->view($failedDeliveryNotifications, Response::HTTP_OK);
return new JsonResponse($failedDeliveryNotifications, Response::HTTP_OK);
}
/**
* @Rest\Patch ("/sms/failed/{station_id}/{sms_id}", name="failed_sms_update")
*/
public function updateManuallySentSMS(Request $request, $station_id,$sms_id)
{
$sms = $this->em->getRepository(Sms::class)->findOneBy([
'id' => $sms_id
]);
$sms->setManuallySent(true);
$this->em->flush();
$failedDeliveryNotifications = $this->em->getRepository(WayBill::class)->findFailedSms($station_id);
// return $this->view($failedDeliveryNotifications, Response::HTTP_OK);
return new JsonResponse($failedDeliveryNotifications, Response::HTTP_OK);
}
}