Passed
Push — dev5 ( a24f56...eeca7a )
by Ron
08:23
created

CustomerSystemsController::destroy()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 12
rs 10
ccs 6
cts 6
cp 1
crap 1
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 20
    public function __construct()
17
    {
18 20
        $this->middleware('auth');
19 20
    }
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
    public function update(CustomerEditEquipmentRequest $request, $id)
47
    {
48
        $updateObj = new SetCustomerEquipment($id);
49
        if(!$updateObj->updateEquipment($request))
50
        {
51
            abort(404);
52
        }
53
54
        return response()->json(['success' => true]);
55
    }
56
57
    //  Delete a system attached to a customer
58
    public function deleteEquip($equipID, $custID)
59
    {
60
        $delObj = new SetCustomerEquipment($custID);
61
        if(!$delObj->deleteEquipment($equipID))
62
        {
63
            return response()->json(['success' => false]);
64
        }
65
66
        return response()->json(['success' => true]);
67
    }
68
}
69