|
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\Issue\AddIssueCommand; |
|
15
|
|
|
use Gitamin\Commands\Issue\RemoveIssueCommand; |
|
16
|
|
|
use Gitamin\Commands\Issue\UpdateIssueCommand; |
|
17
|
|
|
use Gitamin\Models\Issue; |
|
18
|
|
|
use Illuminate\Contracts\Auth\Guard; |
|
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 IssueController extends AbstractApiController |
|
25
|
|
|
{ |
|
26
|
|
|
use DispatchesJobs; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Get all issues. |
|
30
|
|
|
* |
|
31
|
|
|
* @param \Symfony\Component\HttpFoundation\Request $request |
|
32
|
|
|
* @param \Illuminate\Contracts\Auth\Guard $auth |
|
33
|
|
|
* |
|
34
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
35
|
|
|
*/ |
|
36
|
|
|
public function getIssues(Request $request, Guard $auth) |
|
37
|
|
|
{ |
|
38
|
|
|
//$issuePosition = $auth->check() ? 0 : 1; |
|
|
|
|
|
|
39
|
|
|
$issuePosition = $auth->check() ? 0 : -1; |
|
40
|
|
|
|
|
41
|
|
|
$issues = Issue::where('position', '>=', $issuePosition)->paginate($request->get('per_page', 20)); |
|
42
|
|
|
|
|
43
|
|
|
return $this->paginator($issues, $request); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Get a single issue. |
|
48
|
|
|
* |
|
49
|
|
|
* @param \Gitamin\Models\Issue $issue |
|
50
|
|
|
* |
|
51
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
52
|
|
|
*/ |
|
53
|
|
|
public function getIssue(Issue $issue) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->item($issue); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* Create a new issue. |
|
60
|
|
|
* |
|
61
|
|
|
* @param \Illuminate\Contracts\Auth\Guard $auth |
|
62
|
|
|
* |
|
63
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
64
|
|
|
*/ |
|
65
|
|
|
public function postIssues(Request $request, Guard $auth) |
|
|
|
|
|
|
66
|
|
|
{ |
|
67
|
|
|
try { |
|
68
|
|
|
$issue = $this->dispatch(new AddIssueCommand( |
|
69
|
|
|
$request->get('title'), |
|
70
|
|
|
$request->get('description'), |
|
71
|
|
|
$request->get('author_id'), |
|
72
|
|
|
$request->get('project_id') |
|
73
|
|
|
)); |
|
74
|
|
|
} catch (QueryException $e) { |
|
75
|
|
|
throw new BadRequestHttpException(); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
return $this->item($issue); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* Update an existing issue. |
|
83
|
|
|
* |
|
84
|
|
|
* @param \Gitamin\Models\Inicdent $issue |
|
85
|
|
|
* |
|
86
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
87
|
|
|
*/ |
|
88
|
|
View Code Duplication |
public function putIssue(Request $request, Issue $issue) |
|
|
|
|
|
|
89
|
|
|
{ |
|
90
|
|
|
try { |
|
91
|
|
|
$issue = $this->dispatch(new UpdateIssueCommand( |
|
92
|
|
|
$issue, |
|
93
|
|
|
$request->get('title'), |
|
94
|
|
|
$request->get('description'), |
|
95
|
|
|
$request->get('author_id'), |
|
96
|
|
|
$request->get('project_id') |
|
97
|
|
|
)); |
|
98
|
|
|
} catch (QueryException $e) { |
|
99
|
|
|
throw new BadRequestHttpException(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
return $this->item($issue); |
|
103
|
|
|
} |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* Delete an existing issue. |
|
107
|
|
|
* |
|
108
|
|
|
* @param \Gitamin\Models\Issue $issue |
|
109
|
|
|
* |
|
110
|
|
|
* @return \Illuminate\Http\JsonResponse |
|
111
|
|
|
*/ |
|
112
|
|
|
public function deleteIssue(Issue $issue) |
|
113
|
|
|
{ |
|
114
|
|
|
$this->dispatch(new RemoveIssueCommand($issue)); |
|
115
|
|
|
|
|
116
|
|
|
return $this->noContent(); |
|
117
|
|
|
} |
|
118
|
|
|
} |
|
119
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.