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

CustomerSystemsController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 0
loc 12
ccs 7
cts 7
cp 1
crap 1
rs 10
c 1
b 0
f 0
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