NotificationFeedbackController::readAction()   A
last analyzed

Complexity

Conditions 2
Paths 3

Size

Total Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 9.536
c 0
b 0
f 0
cc 2
nc 3
nop 1
1
<?php
2
3
namespace IrishDan\NotificationBundle\Controller;
4
5
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6
use Symfony\Component\HttpFoundation\JsonResponse;
7
8
class NotificationFeedbackController extends Controller
9
{
10
    /**
11
     * Route for setting a notification as read
12
     */
13
    public function readAction($uuid)
14
    {
15
        $databaseNotificationManager = $this->get('notification.database_notification_manager');
16
17
        try {
18
            $databaseNotificationManager->findAndSetAsRead(['uuid' => $uuid]);
19
20
            $code = 200;
21
            $status = 'ok';
22
            $message = sprintf('Database notification %s marked as read', $uuid);
23
        } catch (\Exception $e) {
24
            $code = 500;
25
            $status = 'error';
26
            $message = $e->getMessage();
27
        }
28
29
        return new JsonResponse(
30
            [
31
                'status' => $status,
32
                'message' => $message,
33
            ],
34
            $code
35
        );
36
    }
37
}
38