Skip to content
Snippets Groups Projects
Commit af056ee8 authored by Jeremy Guiselin's avatar Jeremy Guiselin
Browse files

read notifications

parent 072c1b5c
Branches
No related tags found
No related merge requests found
......@@ -157,6 +157,12 @@ class DefaultController extends FOSRestController
return $this->handleView($view);
}
/**
* @param Request $request
* @return Response
*
* @Post("/save-purchase")
*/
public function savePurchaseAction(Request $request)
{
$view = View::create();
......@@ -207,23 +213,30 @@ class DefaultController extends FOSRestController
/**
* @param string $uuid
*
* @return Response
*
* GET Route annotation.
* @Get("/notifications/{uuid}/read")
*/
public function readAllNotificationsAction(string $uuid)
{
$view = View::create();
$device = $this->getDeviceRepository()->findOneBy(['uuid' => $uuid]);
if ($device) {
try {
$this->getNotificationOnDeviceRepository()->readAllNotifications($device);
return $this->handleView($view);
} catch (\Exception $e) {
$view->setStatusCode(400);
$this->getLogger()->err($e->getMessage());
return $this->handleView($view);
}
} else {
}
$view->setStatusCode(400);
$this->getLogger()->err('No device for this uuid');
return $this->handleView($view);
}
private function getNotificationOnDeviceRepository()
......
......@@ -16,10 +16,7 @@ use Doctrine\ORM\EntityRepository;
class NotificationOnDeviceRepository extends EntityRepository
{
public function findNotificationsByDevice(
array $notifications,
Device $device
)
public function findNotificationsByDevice(array $notifications, Device $device)
{
return $this->createQueryBuilder('s')
->where('s.notification IN (:notifications)')
......@@ -32,10 +29,7 @@ class NotificationOnDeviceRepository extends EntityRepository
->getResult();
}
public function updateStatusOnAllDevices(
array $devices,
Notification $notification
)
public function updateStatusOnAllDevices(array $devices, Notification $notification)
{
foreach ($devices as $device) {
$notifOnDevice = new NotificationOnDevice();
......@@ -49,13 +43,14 @@ class NotificationOnDeviceRepository extends EntityRepository
public function readAllNotifications(Device $device)
{
$qb = $this->createQueryBuilder('n');
$qb
->update('n')
->set('n.status', NotificationOnDevice::STATUS_READ)
->where('n.device = :device')
->setParameter('device', $device);
$qb->getQuery()->execute();
$notifications = $this->findBy([
'device' => $device
]);
foreach ($notifications as $notification) {
$notification->setStatus(NotificationOnDevice::STATUS_READ);
}
$this->getEntityManager()->flush();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment