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

CustomerSystemsController   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
dl 0
loc 53
ccs 20
cts 22
cp 0.9091
rs 10
c 1
b 0
f 0
wmc 9

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A show() 0 3 1
A index() 0 3 1
A store() 0 9 2
A deleteEquip() 0 9 2
A update() 0 9 2
1
<?php
2
3
namespace App\Http\Controllers\Customers;
4
5
use App\Http\Controllers\Controller;
6
7
use App\Domains\Equipment\GetEquipmentData;
8
use App\Domains\Customers\SetCustomerEquipment;
9
use App\Domains\Customers\GetCustomerEquipment;
10
11
use App\Http\Requests\CustomerNewEquipmentRequest;
12
use App\Http\Requests\CustomerEditEquipmentRequest;
13
14
class CustomerSystemsController extends Controller
15
{
16 28
    public function __construct()
17
    {
18 28
        $this->middleware('auth');
19 28
    }
20
21
    //  Get the possible system types that can be assigned to the customer
22 2
    public function index()
23
    {
24 2
        return  (new GetEquipmentData)->getAllEquipmentWithDataList();
25
    }
26
27
    //  Store a new system for the customer
28 4
    public function store(CustomerNewEquipmentRequest $request)
29
    {
30 4
        $equipObj = new SetCustomerEquipment($request->cust_id);
31 4
        if(!$equipObj->creatNewEquipment($request))
32
        {
33
            abort(404);
34
        }
35
36 4
        return response()->json(['success' => true]);
37
    }
38
39
    //  Get the list of systems attached to the customer
40 6
    public function show($id)
41
    {
42 6
        return (new GetCustomerEquipment($id))->execute();
43
    }
44
45
    // Update the customers system data
46 4
    public function update(CustomerEditEquipmentRequest $request, $id)
47
    {
48 4
        $updateObj = new SetCustomerEquipment($id);
49 4
        if(!$updateObj->updateEquipment($request))
50
        {
51 2
            abort(404);
52
        }
53
54 2
        return response()->json(['success' => true]);
55
    }
56
57
    //  Delete a system attached to a customer
58 2
    public function deleteEquip($equipID, $custID)
59
    {
60 2
        $delObj = new SetCustomerEquipment($custID);
61 2
        if(!$delObj->deleteEquipment($equipID))
62
        {
63
            return response()->json(['success' => false]);
64
        }
65
66 2
        return response()->json(['success' => true]);
67
    }
68
}
69