Passed
Push — dev5a ( 328ab1...cf3a23 )
by Ron
07:38
created

CustomerFilesController::update()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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