|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Modules\Example\Http\Controllers\Api\V1; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Routing\Controller; |
|
6
|
|
|
use Modules\Core\Supports\Response; |
|
7
|
|
|
use Modules\Core\Supports\ResponsibilityChain; |
|
8
|
|
|
use Modules\Example\Http\Requests\ExampleStoreRequest; |
|
9
|
|
|
use Modules\Example\Http\Requests\ExampleUpdateRequest; |
|
10
|
|
|
use Modules\Example\Services\ExampleService; |
|
11
|
|
|
|
|
12
|
|
|
class ExampleControllerI extends Controller implements ExampleController |
|
13
|
|
|
{ |
|
14
|
|
|
public function index(ResponsibilityChain $responsibilityChain, ExampleService $exampleService): Response |
|
15
|
|
|
{ |
|
16
|
|
|
$step1 = function () use ($exampleService) { |
|
17
|
|
|
return $exampleService->index(); |
|
18
|
|
|
}; |
|
19
|
|
|
|
|
20
|
|
|
return $responsibilityChain->append($step1)->handle(); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
public function store( |
|
24
|
|
|
ResponsibilityChain $responsibilityChain, |
|
25
|
|
|
ExampleService $exampleService, |
|
26
|
|
|
ExampleStoreRequest $exampleStoreRequest |
|
27
|
|
|
): Response { |
|
28
|
|
|
$attributes = $exampleStoreRequest->validated(); |
|
29
|
|
|
|
|
30
|
|
|
$step1 = function () use ($exampleService, $attributes) { |
|
31
|
|
|
return $exampleService->store($attributes); |
|
32
|
|
|
}; |
|
33
|
|
|
|
|
34
|
|
|
return $responsibilityChain->append($step1)->handle(); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function show(ResponsibilityChain $responsibilityChain, ExampleService $exampleService, int $id): Response |
|
38
|
|
|
{ |
|
39
|
|
|
$step1 = function () use ($exampleService, $id) { |
|
40
|
|
|
return $exampleService->show($id); |
|
41
|
|
|
}; |
|
42
|
|
|
|
|
43
|
|
|
return $responsibilityChain->append($step1)->handle(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public function update( |
|
47
|
|
|
ResponsibilityChain $responsibilityChain, |
|
48
|
|
|
ExampleService $exampleService, |
|
49
|
|
|
int $id, |
|
50
|
|
|
ExampleUpdateRequest $exampleUpdateRequest |
|
51
|
|
|
): Response { |
|
52
|
|
|
$attributes = $exampleUpdateRequest->validated(); |
|
53
|
|
|
|
|
54
|
|
|
$step1 = function () use ($exampleService, $id, $attributes) { |
|
55
|
|
|
return $exampleService->update($id, $attributes); |
|
56
|
|
|
}; |
|
57
|
|
|
|
|
58
|
|
|
return $responsibilityChain->append($step1)->handle(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
public function destroy(ResponsibilityChain $responsibilityChain, ExampleService $exampleService, int $id): Response |
|
62
|
|
|
{ |
|
63
|
|
|
$step1 = function () use ($exampleService, $id) { |
|
64
|
|
|
return $exampleService->destroy($id); |
|
65
|
|
|
}; |
|
66
|
|
|
|
|
67
|
|
|
return $responsibilityChain->append($step1)->handle(); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|