Passed
Push — master ( 1d6d9a...2a90e7 )
by Ron
02:47 queued 12s
created

DashboardController::markNotification()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1.037

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 5
ccs 2
cts 3
cp 0.6667
crap 1.037
rs 10
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Auth;
6
7
use App\Domains\Users\GetUserStats;
8
use App\Domains\TechTips\GetTechTipStats;
9
use App\Domains\Users\MarkUserNotifications;
10
11
class DashboardController extends Controller
12
{
13 22
    public function __construct()
14
    {
15
        //  Only authorized users have access to these pages
16 22
        $this->middleware('auth');
17 22
    }
18
19
    //  Dashboard is the Logged In User home landing page
20 2
    public function index()
21
    {
22 2
        $userStats = new GetUserStats;
23 2
        $tipStats  = new GetTechTipStats;
24
25 2
        return view('dashboard', [
26 2
            'custFavs'    => $userStats->getUserCustomerFavs(),
27 2
            'tipFavs'     => $userStats->getUserTechTipFavs(),
28 2
            'tips30'      => $tipStats->getTipsInLastDays(30),
29 2
            'tipsAll'     => $tipStats->getTotalTechTipCount(),
30 2
            'activeLinks' => $userStats->getUserActiveFileLinks(),
31 2
            'totalLinks'  => $userStats->getUserTotalLinks(),
32
        ]);
33
    }
34
35
    //  Get the users notifications
36
    public function getNotifications()
37
    {
38
        return Auth::user()->notifications;
39
    }
40
41
    //  Mark a notification as read
42 4
    public function markNotification($id)
43
    {
44 4
        (new MarkUserNotifications)->markNotificationRead($id);
45
46
        return response()->json(['success' => true]);
47
    }
48
49
    //  Delte a user notification
50 4
    public function delNotification($id)
51
    {
52 4
        (new MarkUserNotifications)->deleteNotification($id);
53
54
        return response()->json(['success' => true]);
55
    }
56
57
    //  About page
58 2
    public function about()
59
    {
60 2
        return view('about');
61
    }
62
}
63