Passed
Push — master ( f51c1b...16736d )
by Arthur
05:36
created

NotificationController   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A allUnread() 0 3 1
A all() 0 3 1
A read() 0 6 1
A unread() 0 6 1
A __construct() 0 3 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 14.10.18
6
 * Time: 18:58.
7
 */
8
9
namespace Modules\Notification\Http\Controllers;
10
11
use Illuminate\Routing\Controller;
12
use Modules\Notification\Contracts\NotificationServiceContract;
13
use Modules\Notification\Resources\NotificationResource;
14
15
class NotificationController extends Controller
16
{
17
    protected $service;
18
19
    /**
20
     * NotificationController constructor.
21
     * @param $service
22
     */
23
    public function __construct(NotificationServiceContract $service)
24
    {
25
        $this->service = $service;
26
    }
27
28
    public function all()
29
    {
30
        return NotificationResource::collection($this->service->allNotificationsByUser(get_authenticated_user()));
31
    }
32
33
    public function allUnread()
34
    {
35
        return NotificationResource::collection($this->service->unreadNotifcationsByUser(get_authenticated_user()));
36
    }
37
38
    public function read($id)
39
    {
40
        $this->service->markAsRead($id);
41
42
        return response()->json([
43
            'success',
44
        ]);
45
    }
46
47
    public function unread($id)
48
    {
49
        $this->service->markAsUnread($id);
50
51
        return response()->json([
52
            'success',
53
        ]);
54
    }
55
}
56