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\ProjectNamespace\AddProjectNamespaceCommand; |
15
|
|
|
use Gitamin\Commands\ProjectNamespace\RemoveProjectNamespaceCommand; |
16
|
|
|
use Gitamin\Commands\ProjectNamespace\UpdateProjectNamespaceCommand; |
17
|
|
|
use Gitamin\Models\ProjectNamespace; |
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 ProjectNamespaceController extends AbstractApiController |
25
|
|
|
{ |
26
|
|
|
use DispatchesJobs; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Get all teams. |
30
|
|
|
* |
31
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
32
|
|
|
* |
33
|
|
|
* @return \Illuminate\Http\JsonResponse |
34
|
|
|
*/ |
35
|
|
|
public function getTeams(Request $request) |
36
|
|
|
{ |
37
|
|
|
$teams = ProjectNamespace::paginate(Binput::get('per_page', 20)); |
38
|
|
|
|
39
|
|
|
return $this->paginator($teams, $request); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Get a single team. |
44
|
|
|
* |
45
|
|
|
* @param \Gitamin\Models\ProjectNamespace $team |
46
|
|
|
* |
47
|
|
|
* @return \Illuminate\Http\JsonResponse |
48
|
|
|
*/ |
49
|
|
|
public function getTeam(ProjectNamespace $team) |
50
|
|
|
{ |
51
|
|
|
return $this->item($team); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Create a new project team. |
56
|
|
|
* |
57
|
|
|
* @return \Illuminate\Http\JsonResponse |
58
|
|
|
*/ |
59
|
|
View Code Duplication |
public function postTeams() |
|
|
|
|
60
|
|
|
{ |
61
|
|
|
try { |
62
|
|
|
$team = $this->dispatch(new AddProjectNamespaceCommand( |
|
|
|
|
63
|
|
|
Binput::get('name'), |
64
|
|
|
Binput::get('path'), |
65
|
|
|
Binput::get('order', 0) |
66
|
|
|
)); |
67
|
|
|
} catch (QueryException $e) { |
68
|
|
|
throw new BadRequestHttpException(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
return $this->item($team); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Update an existing team. |
76
|
|
|
* |
77
|
|
|
* @param \Gitamin\Models\ProjectNamespace $team |
78
|
|
|
* |
79
|
|
|
* @return \Illuminate\Http\JsonResponse |
80
|
|
|
*/ |
81
|
|
View Code Duplication |
public function putTeam(ProjectNamespace $team) |
|
|
|
|
82
|
|
|
{ |
83
|
|
|
try { |
84
|
|
|
$team = $this->dispatch(new UpdateProjectNamespaceCommand( |
|
|
|
|
85
|
|
|
$team, |
|
|
|
|
86
|
|
|
Binput::get('name'), |
87
|
|
|
Binput::get('path'), |
88
|
|
|
Binput::get('order', 0) |
89
|
|
|
)); |
90
|
|
|
} catch (QueryException $e) { |
91
|
|
|
throw new BadRequestHttpException(); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
return $this->item($team); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* Delete an existing team. |
99
|
|
|
* |
100
|
|
|
* @param \Gitamin\Models\ProjectNamespace $team |
101
|
|
|
* |
102
|
|
|
* @return \Illuminate\Http\JsonResponse |
103
|
|
|
*/ |
104
|
|
|
public function deleteTeam(ProjectNamespace $team) |
105
|
|
|
{ |
106
|
|
|
$this->dispatch(new RemoveProjectNamespaceCommand($team)); |
107
|
|
|
|
108
|
|
|
return $this->noContent(); |
109
|
|
|
} |
110
|
|
|
} |
111
|
|
|
|
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.