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

read notifications

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