<?php
namespace App\Controller\Api;
use App\Entity\Customer;
use App\Entity\Notification;
use App\Entity\NotificationAutomatic;
use App\Repository\NotificationAutomaticRepository;
use App\Repository\NotificationRepository;
use App\Services\Api\NotificationManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Contracts\Translation\TranslatorInterface;
class NotificationController extends ApiController
{
/** @var NotificationManager $notificationManager */
protected $notificationManager;
public function __construct(EntityManagerInterface $em, ParameterBagInterface $parameterBag, NotificationManager $notificationManager)
{
parent::__construct($em, $parameterBag);
$this->notificationManager = $notificationManager;
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/notification/list", name="api_notification_list", methods={"POST"})
*/
public function list(Request $request)
{
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$prefixFile = $this->getParameter("app.path.type_notification_images");
$prefixFileAutomatic = $this->getParameter("app.path.notification_automatic_message_images");
$prefixFileGame = $this->getParameter("app.path.game_images");
$folderImageNotification = $baseurl . $prefixFile . "/";
$folderImageGame = $baseurl . $prefixFileGame . "/";
$folderImageNotificationAutomatic = $baseurl . $prefixFileAutomatic . "/";
/** @var Customer $notification */
$customer = $this->getUser();
/** @var NotificationRepository $notificationRepository */
$notificationRepository = $this->em->getRepository(Notification::class);
$locale = $request->getLocale();
$generals = $notificationRepository->getNotificationCustomer($customer, $locale, $folderImageNotification, $folderImageGame, $folderImageNotificationAutomatic);
return $this->response([
'list' => $generals,
'code' => 200
]);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/notification/remove/{notificationId}", name="api_notification_remove", methods={"POST"})
*/
public function remove($notificationId, Request $request)
{
/** @var Customer $notification */
$customer = $this->getUser();
$customerId = $customer->getId();
$results = $this->notificationManager->remove($notificationId, $customerId);
return $this->response($results);
}
/**
* @param Request $request
* @return JsonResponse
*
* @Route("/notification/read/{notificationId}", name="api_notification_read", methods={"POST"})
*/
public function read($notificationId, Request $request)
{
/** @var Customer $notification */
$customer = $this->getUser();
$customerId = $customer->getId();
$results = $this->notificationManager->read($notificationId, $customerId);
return $this->response($results);
}
}