1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of Gitamin. |
5
|
|
|
* |
6
|
|
|
* Copyright (C) 2015-2016 The Gitamin Team |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gitamin\Http\Controllers\Api; |
13
|
|
|
|
14
|
|
|
use Gitamin\Commands\Owner\AddOwnerCommand; |
15
|
|
|
use Gitamin\Commands\Owner\RemoveOwnerCommand; |
16
|
|
|
use Gitamin\Commands\Owner\UpdateOwnerCommand; |
17
|
|
|
use Gitamin\Models\Owner; |
18
|
|
|
use GrahamCampbell\Binput\Facades\Binput; |
19
|
|
|
use Illuminate\Database\QueryException; |
20
|
|
|
use Illuminate\Foundation\Bus\DispatchesJobs; |
21
|
|
|
use Illuminate\Http\Request; |
22
|
|
|
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException; |
23
|
|
|
|
24
|
|
|
class OwnerController extends AbstractApiController |
25
|
|
|
{ |
26
|
|
|
use DispatchesJobs; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get all owners. |
30
|
|
|
* |
31
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Http\JsonResponse |
34
|
|
|
*/ |
35
|
|
|
public function getOwners(Request $request) |
36
|
|
|
{ |
37
|
|
|
$owners = Owner::paginate(Binput::get('per_page', 20)); |
38
|
|
|
|
39
|
|
|
return $this->paginator($owners, $request); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get a single owner. |
44
|
|
|
* |
45
|
|
|
* @param \Gitamin\Models\Owner $owner |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Http\JsonResponse |
48
|
|
|
*/ |
49
|
|
|
public function getOwner(Owner $owner) |
50
|
|
|
{ |
51
|
|
|
return $this->item($owner); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Create a new project team. |
56
|
|
|
* |
57
|
|
|
* @return \Illuminate\Http\JsonResponse |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function postOwners() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
try { |
62
|
|
|
$owner = $this->dispatch(new AddOwnerCommand( |
63
|
|
|
Binput::get('name'), |
64
|
|
|
Binput::get('path'), |
65
|
|
|
Binput::get('user_id'), |
66
|
|
|
Binput::get('description'), |
67
|
|
|
Binput::get('type') |
68
|
|
|
)); |
69
|
|
|
} catch (QueryException $e) { |
70
|
|
|
throw new BadRequestHttpException(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
return $this->item($owner); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Update an existing owner. |
78
|
|
|
* |
79
|
|
|
* @param \Gitamin\Models\Owner $owner |
80
|
|
|
* |
81
|
|
|
* @return \Illuminate\Http\JsonResponse |
82
|
|
|
*/ |
83
|
|
View Code Duplication |
public function putOwner(Owner $owner) |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
try { |
86
|
|
|
$owner = $this->dispatch(new UpdateOwnerCommand( |
87
|
|
|
$owner, |
|
|
|
|
88
|
|
|
Binput::get('name'), |
89
|
|
|
Binput::get('path'), |
90
|
|
|
Binput::get('user_id'), |
91
|
|
|
Binput::get('description'), |
92
|
|
|
Binput::get('type') |
|
|
|
|
93
|
|
|
)); |
94
|
|
|
} catch (QueryException $e) { |
95
|
|
|
throw new BadRequestHttpException(); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $this->item($owner); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* Delete an existing owner. |
103
|
|
|
* |
104
|
|
|
* @param \Gitamin\Models\Owner $owner |
105
|
|
|
* |
106
|
|
|
* @return \Illuminate\Http\JsonResponse |
107
|
|
|
*/ |
108
|
|
|
public function deleteOwner(Owner $owner) |
109
|
|
|
{ |
110
|
|
|
$this->dispatch(new RemoveOwnerCommand($owner)); |
111
|
|
|
|
112
|
|
|
return $this->noContent(); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.