|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Http\Controllers\API; |
|
4
|
|
|
|
|
5
|
|
|
use App\Http\Requests\Tournament\RemoveTeam; |
|
6
|
|
|
use App\League; |
|
7
|
|
|
use App\Team; |
|
8
|
|
|
use App\TournamentTeam; |
|
9
|
|
|
use App\Transformers\TeamSearchTransformer; |
|
10
|
|
|
use App\Transformers\TeamTransformer; |
|
11
|
|
|
use App\Transformers\TournamentTeamTransformer; |
|
12
|
|
|
use Illuminate\Support\Facades\Input; |
|
13
|
|
|
use App\Http\Requests\CreateTeam; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class TeamController |
|
17
|
|
|
* @package App\Http\Controllers\API |
|
18
|
|
|
*/ |
|
19
|
|
|
class TeamController extends Controller |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @SWG\Get( |
|
23
|
|
|
* tags={"Team"}, |
|
24
|
|
|
* path="/api/v1/teams/all", |
|
25
|
|
|
* description="Returns all teams from the database", |
|
26
|
|
|
* operationId="catalogue", |
|
27
|
|
|
* produces={"application/json"}, |
|
28
|
|
|
* @SWG\Response( |
|
29
|
|
|
* response="200", |
|
30
|
|
|
* description="Successfully get list of teams" |
|
31
|
|
|
* ) |
|
32
|
|
|
* ) |
|
33
|
|
|
*/ |
|
34
|
|
|
public function catalogue() |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->response->collection(Team::all(), new TeamTransformer(), 'teams'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @SWG\Get( |
|
41
|
|
|
* tags={"Team"}, |
|
42
|
|
|
* path="/api/v1/teams/{teamId}", |
|
43
|
|
|
* description="Returns specified team from tournament", |
|
44
|
|
|
* operationId="find", |
|
45
|
|
|
* produces={"application/json"}, |
|
46
|
|
|
* @SWG\Parameter( |
|
47
|
|
|
* description="Team id", |
|
48
|
|
|
* in="path", |
|
49
|
|
|
* name="teamId", |
|
50
|
|
|
* required=true, |
|
51
|
|
|
* type="integer" |
|
52
|
|
|
* ), |
|
53
|
|
|
* @SWG\Response( |
|
54
|
|
|
* response="200", |
|
55
|
|
|
* description="Successfully get specified team" |
|
56
|
|
|
* ) |
|
57
|
|
|
* ) |
|
58
|
|
|
* @param $teamId |
|
59
|
|
|
* @return array |
|
60
|
|
|
*/ |
|
61
|
|
|
public function find($teamId) |
|
62
|
|
|
{ |
|
63
|
|
|
$collection = TournamentTeam::where(['teamId' => $teamId]); |
|
64
|
|
|
|
|
65
|
|
|
return $this->response->collection($collection->get(), new TournamentTeamTransformer(), 'teams'); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @SWG\Get( |
|
70
|
|
|
* tags={"Team"}, |
|
71
|
|
|
* path="/api/v1/teams/search", |
|
72
|
|
|
* description="Returns teams we search from database", |
|
73
|
|
|
* operationId="search", |
|
74
|
|
|
* produces={"application/json"}, |
|
75
|
|
|
* @SWG\Parameter( |
|
76
|
|
|
* description="First letters of team name", |
|
77
|
|
|
* in="query", |
|
78
|
|
|
* name="term", |
|
79
|
|
|
* required=true, |
|
80
|
|
|
* type="string" |
|
81
|
|
|
* ), |
|
82
|
|
|
* @SWG\Response( |
|
83
|
|
|
* response="200", |
|
84
|
|
|
* description="Successfully get teams we search" |
|
85
|
|
|
* ) |
|
86
|
|
|
* ) |
|
87
|
|
|
*/ |
|
88
|
|
|
public function search() |
|
89
|
|
|
{ |
|
90
|
|
|
$collection = Team::with('tournamentTeams.tournament')->where('name', 'ilike', strtolower(Input::get('term')) . '%')->get(); |
|
|
|
|
|
|
91
|
|
|
|
|
92
|
|
|
return $this->response->collection( |
|
93
|
|
|
$collection, |
|
94
|
|
|
new TeamSearchTransformer(), |
|
95
|
|
|
'teams' |
|
96
|
|
|
); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* @SWG\Delete( |
|
101
|
|
|
* tags={"Team"}, |
|
102
|
|
|
* path="/api/v1/teams/{teamId}", |
|
103
|
|
|
* description="Delete specified team from tournament", |
|
104
|
|
|
* operationId="remove", |
|
105
|
|
|
* produces={"application/json"}, |
|
106
|
|
|
* @SWG\Parameter( |
|
107
|
|
|
* description="Team id", |
|
108
|
|
|
* in="path", |
|
109
|
|
|
* name="teamId", |
|
110
|
|
|
* required=true, |
|
111
|
|
|
* type="integer" |
|
112
|
|
|
* ), |
|
113
|
|
|
* @SWG\Response( |
|
114
|
|
|
* response="200", |
|
115
|
|
|
* description="Successfully remove specified team" |
|
116
|
|
|
* ) |
|
117
|
|
|
* ) |
|
118
|
|
|
* @param $teamId |
|
119
|
|
|
* @return |
|
120
|
|
|
*/ |
|
121
|
|
|
public function remove($teamId) |
|
122
|
|
|
{ |
|
123
|
|
|
return TournamentTeam::where(['teamId' => $teamId])->delete(); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* @SWG\Post( |
|
128
|
|
|
* tags={"Team"}, |
|
129
|
|
|
* path="/api/v1/leagueTeams", |
|
130
|
|
|
* description="Add new team to database", |
|
131
|
|
|
* operationId="store", |
|
132
|
|
|
* produces={"application/json"}, |
|
133
|
|
|
* @SWG\Parameter( |
|
134
|
|
|
* description="League id", |
|
135
|
|
|
* in="formData", |
|
136
|
|
|
* name="team[leagueId]", |
|
137
|
|
|
* required=true, |
|
138
|
|
|
* type="integer" |
|
139
|
|
|
* ), |
|
140
|
|
|
* @SWG\Parameter( |
|
141
|
|
|
* description="Team name", |
|
142
|
|
|
* in="formData", |
|
143
|
|
|
* name="team[name]", |
|
144
|
|
|
* required=true, |
|
145
|
|
|
* type="string" |
|
146
|
|
|
* ), |
|
147
|
|
|
* @SWG\Parameter( |
|
148
|
|
|
* description="Team logo", |
|
149
|
|
|
* in="formData", |
|
150
|
|
|
* name="team[logoPath]", |
|
151
|
|
|
* required=false, |
|
152
|
|
|
* type="file" |
|
153
|
|
|
* ), |
|
154
|
|
|
* @SWG\Response( |
|
155
|
|
|
* response="200", |
|
156
|
|
|
* description="Successfully add new team" |
|
157
|
|
|
* ) |
|
158
|
|
|
* ) |
|
159
|
|
|
*/ |
|
160
|
|
|
public function store(CreateTeam $request) |
|
161
|
|
|
{ |
|
162
|
|
|
$team = new Team(); |
|
163
|
|
|
$team = $team->addTeam($request); |
|
164
|
|
|
|
|
165
|
|
|
return $this->response->collection(Team::where(['id' => $team->id])->get(), new TeamTransformer(), 'leagueTeams'); |
|
|
|
|
|
|
166
|
|
|
} |
|
167
|
|
|
|
|
168
|
|
|
/** |
|
169
|
|
|
* @SWG\Delete( |
|
170
|
|
|
* tags={"Team"}, |
|
171
|
|
|
* path="/api/v1/leagueTeams/{teamId}", |
|
172
|
|
|
* description="Delete specified team from database", |
|
173
|
|
|
* operationId="delete", |
|
174
|
|
|
* produces={"application/json"}, |
|
175
|
|
|
* @SWG\Parameter( |
|
176
|
|
|
* description="Team id", |
|
177
|
|
|
* in="path", |
|
178
|
|
|
* name="teamId", |
|
179
|
|
|
* required=true, |
|
180
|
|
|
* type="integer" |
|
181
|
|
|
* ), |
|
182
|
|
|
* @SWG\Response( |
|
183
|
|
|
* response="200", |
|
184
|
|
|
* description="Successfully remove specified team" |
|
185
|
|
|
* ) |
|
186
|
|
|
* ) |
|
187
|
|
|
*/ |
|
188
|
|
|
public function delete($id) |
|
189
|
|
|
{ |
|
190
|
|
|
TournamentTeam::where(['teamId' => $id])->delete(); |
|
191
|
|
|
return Team::where(['id' => $id])->delete(); |
|
192
|
|
|
} |
|
193
|
|
|
} |
|
194
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: