Passed
Push — dev5a ( e86993...328ab1 )
by Ron
10:15 queued 39s
created

CustomerFilesController::index()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Http\Controllers\Customers;
4
5
use App\Domains\Customers\getCustomerFiles;
6
use App\Domains\Customers\setCustomerFiles;
7
use App\Domains\Files\GetCustomerFileTypes;
8
use App\Http\Controllers\Controller;
9
use App\Http\Requests\Customers\EditFileRequest;
10
use App\Http\Requests\Customers\NewFileRequest;
11
use Illuminate\Http\Request;
12
use Illuminate\Support\Facades\Auth;
13
use Illuminate\Support\Facades\Log;
14
15
class CustomerFilesController extends Controller
16
{
17
    //  Index will get the types of files that can be assigned to a customer
18 2
    public function index()
19
    {
20 2
        return (new GetCustomerFileTypes)->execute();
21
    }
22
23
    //  Store a new customer file
24
    public function store(NewFileRequest $request)
25
    {
26
        if((new setCustomerFiles)->createFile($request, Auth::user()->user_id))
27
        {
28
            return response()->json(['success' => true]);
29
        }
30
31
        return response()->json(['success' => false]);
32
    }
33
34
    //  Get the customers files
35 2
    public function show($id)
36
    {
37 2
        return (new getCustomerFiles)->execute($id);
38
    }
39
40
    //  Update the basic information of a file without changing the physical file
41 2
    public function update(EditFileRequest $request, $id)
42
    {
43 2
        (new setCustomerFiles)->updateFile($request, $id);
44 2
        return response()->json(['success' => true]);
45
    }
46
47
    //  Delete a file
48 2
    public function destroy($id)
49
    {
50 2
        (new SetCustomerFiles)->deleteCustFile($id);
51 2
        Log::info('User '.Auth::user()->full_name.' deleted file ID '.$id);
52 2
        return response()->json(['success' => true]);
53
    }
54
}
55