@@ -10,195 +10,195 @@ |
||
10 | 10 | use \App\Lib\DsManager\Models\Orm\Coach; |
11 | 11 | |
12 | 12 | $configuration = [ |
13 | - 'settings' => [ |
|
14 | - 'displayErrorDetails' => true, |
|
15 | - ], |
|
13 | + 'settings' => [ |
|
14 | + 'displayErrorDetails' => true, |
|
15 | + ], |
|
16 | 16 | ]; |
17 | 17 | $c = new \Slim\Container($configuration); |
18 | 18 | $api = new \Slim\App($c); |
19 | 19 | |
20 | 20 | $api->get('/ping', function ($request, $response, $args) { |
21 | - $jsonResp = json_encode( |
|
22 | - [ |
|
23 | - "status" => "service up", |
|
24 | - "message" => "in a bottle", |
|
25 | - "config" => \App\Lib\Helpers\Config::get("config1.stuff") |
|
26 | - ] |
|
27 | - ); |
|
28 | - return Responder::getJsonResponse($jsonResp, $response); |
|
21 | + $jsonResp = json_encode( |
|
22 | + [ |
|
23 | + "status" => "service up", |
|
24 | + "message" => "in a bottle", |
|
25 | + "config" => \App\Lib\Helpers\Config::get("config1.stuff") |
|
26 | + ] |
|
27 | + ); |
|
28 | + return Responder::getJsonResponse($jsonResp, $response); |
|
29 | 29 | }); |
30 | 30 | |
31 | 31 | $api->get('/players', function ($request, $response, $args) { |
32 | - $json = json_encode(Player::all()); |
|
33 | - return Responder::getJsonResponse($json, $response); |
|
32 | + $json = json_encode(Player::all()); |
|
33 | + return Responder::getJsonResponse($json, $response); |
|
34 | 34 | }); |
35 | 35 | |
36 | 36 | |
37 | 37 | $api->get('/players/{id}', function ($request, $response, $args) { |
38 | - return Responder::getJsonResponse( |
|
39 | - Player::findOrFail($args['id']), |
|
40 | - $response |
|
41 | - ); |
|
38 | + return Responder::getJsonResponse( |
|
39 | + Player::findOrFail($args['id']), |
|
40 | + $response |
|
41 | + ); |
|
42 | 42 | }); |
43 | 43 | |
44 | 44 | $api->get('/coaches', function ($request, $response, $args) { |
45 | - return Responder::getJsonResponse( |
|
46 | - Coach::all(), |
|
47 | - $response |
|
48 | - ); |
|
45 | + return Responder::getJsonResponse( |
|
46 | + Coach::all(), |
|
47 | + $response |
|
48 | + ); |
|
49 | 49 | }); |
50 | 50 | |
51 | 51 | $api->get('/teams', function ($request, $response, $args) { |
52 | - return Responder::getJsonResponse( |
|
53 | - Team::all(), |
|
54 | - $response |
|
55 | - ); |
|
52 | + return Responder::getJsonResponse( |
|
53 | + Team::all(), |
|
54 | + $response |
|
55 | + ); |
|
56 | 56 | }); |
57 | 57 | |
58 | 58 | $api->get('/teams/{id}', function ($request, $response, $args) { |
59 | - return Responder::getJsonResponse( |
|
60 | - Team::with( |
|
61 | - 'roster', |
|
62 | - 'coach' |
|
63 | - )->where( |
|
64 | - [ |
|
65 | - 'id' => $args['id'] |
|
66 | - ] |
|
67 | - )->get(), |
|
68 | - $response |
|
69 | - ); |
|
59 | + return Responder::getJsonResponse( |
|
60 | + Team::with( |
|
61 | + 'roster', |
|
62 | + 'coach' |
|
63 | + )->where( |
|
64 | + [ |
|
65 | + 'id' => $args['id'] |
|
66 | + ] |
|
67 | + )->get(), |
|
68 | + $response |
|
69 | + ); |
|
70 | 70 | }); |
71 | 71 | |
72 | 72 | $api->get('/teams/{id}/players', function ($request, $response, $args) { |
73 | - return Responder::getJsonResponse( |
|
74 | - Team::with( |
|
75 | - 'roster' |
|
76 | - )->where( |
|
77 | - [ |
|
78 | - 'id' => $args['id'] |
|
79 | - ] |
|
80 | - )->get(), |
|
81 | - $response |
|
82 | - ); |
|
73 | + return Responder::getJsonResponse( |
|
74 | + Team::with( |
|
75 | + 'roster' |
|
76 | + )->where( |
|
77 | + [ |
|
78 | + 'id' => $args['id'] |
|
79 | + ] |
|
80 | + )->get(), |
|
81 | + $response |
|
82 | + ); |
|
83 | 83 | }); |
84 | 84 | |
85 | 85 | $api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) { |
86 | - return Responder::getJsonResponse( |
|
87 | - Player::where( |
|
88 | - [ |
|
89 | - 'id' => $args['playerId'], |
|
90 | - 'team_id' => $args['id'] |
|
91 | - ] |
|
92 | - )->get(), |
|
93 | - $response |
|
94 | - ); |
|
86 | + return Responder::getJsonResponse( |
|
87 | + Player::where( |
|
88 | + [ |
|
89 | + 'id' => $args['playerId'], |
|
90 | + 'team_id' => $args['id'] |
|
91 | + ] |
|
92 | + )->get(), |
|
93 | + $response |
|
94 | + ); |
|
95 | 95 | }); |
96 | 96 | |
97 | 97 | $api->get('/teams/{id}/coach', function ($request, $response, $args) { |
98 | - return Responder::getJsonResponse( |
|
99 | - Team::with( |
|
100 | - 'coach' |
|
101 | - )->where( |
|
102 | - [ |
|
103 | - 'id' => $args['id'] |
|
104 | - ] |
|
105 | - )->get(), |
|
106 | - $response |
|
107 | - ); |
|
98 | + return Responder::getJsonResponse( |
|
99 | + Team::with( |
|
100 | + 'coach' |
|
101 | + )->where( |
|
102 | + [ |
|
103 | + 'id' => $args['id'] |
|
104 | + ] |
|
105 | + )->get(), |
|
106 | + $response |
|
107 | + ); |
|
108 | 108 | }); |
109 | 109 | |
110 | 110 | $api->get('/matches', function ($request, $response, $args) { |
111 | - return Responder::getJsonResponse( |
|
112 | - \App\Lib\DsManager\Models\Orm\Match::with( |
|
113 | - 'homeTeam', |
|
114 | - 'awayTeam' |
|
115 | - )->get(), |
|
116 | - $response |
|
117 | - ); |
|
111 | + return Responder::getJsonResponse( |
|
112 | + \App\Lib\DsManager\Models\Orm\Match::with( |
|
113 | + 'homeTeam', |
|
114 | + 'awayTeam' |
|
115 | + )->get(), |
|
116 | + $response |
|
117 | + ); |
|
118 | 118 | }); |
119 | 119 | |
120 | 120 | $api->post('/matches', function ($request, $response, $args) { |
121 | - $json = $request->getBody(); |
|
122 | - $json = json_decode($json, true); |
|
123 | - return Responder::getJsonResponse( |
|
124 | - \App\Lib\DsManager\Models\Orm\Match::create( |
|
125 | - $json |
|
126 | - ), |
|
127 | - $response |
|
128 | - ); |
|
121 | + $json = $request->getBody(); |
|
122 | + $json = json_decode($json, true); |
|
123 | + return Responder::getJsonResponse( |
|
124 | + \App\Lib\DsManager\Models\Orm\Match::create( |
|
125 | + $json |
|
126 | + ), |
|
127 | + $response |
|
128 | + ); |
|
129 | 129 | }); |
130 | 130 | |
131 | 131 | $api->get('/matches/{id}', function ($request, $response, $args) { |
132 | - return Responder::getJsonResponse( |
|
133 | - \App\Lib\DsManager\Models\Orm\Match::with( |
|
134 | - 'homeTeam', |
|
135 | - 'homeTeam.roster', |
|
136 | - 'homeTeam.coach', |
|
137 | - 'awayTeam', |
|
138 | - 'awayTeam.roster', |
|
139 | - 'awayTeam.coach' |
|
140 | - )->where( |
|
141 | - [ |
|
142 | - 'id' => $args['id'] |
|
143 | - ] |
|
144 | - )->first(), |
|
145 | - $response |
|
146 | - ); |
|
132 | + return Responder::getJsonResponse( |
|
133 | + \App\Lib\DsManager\Models\Orm\Match::with( |
|
134 | + 'homeTeam', |
|
135 | + 'homeTeam.roster', |
|
136 | + 'homeTeam.coach', |
|
137 | + 'awayTeam', |
|
138 | + 'awayTeam.roster', |
|
139 | + 'awayTeam.coach' |
|
140 | + )->where( |
|
141 | + [ |
|
142 | + 'id' => $args['id'] |
|
143 | + ] |
|
144 | + )->first(), |
|
145 | + $response |
|
146 | + ); |
|
147 | 147 | }); |
148 | 148 | |
149 | 149 | $api->get('/matches/{id}/result', function ($request, $response, $args) { |
150 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
151 | - ->where( |
|
152 | - [ |
|
153 | - 'id' => $args['id'] |
|
154 | - ] |
|
155 | - )->first(); |
|
156 | - |
|
157 | - return Responder::getJsonResponse( |
|
158 | - $result, |
|
159 | - $response |
|
160 | - ); |
|
150 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
151 | + ->where( |
|
152 | + [ |
|
153 | + 'id' => $args['id'] |
|
154 | + ] |
|
155 | + )->first(); |
|
156 | + |
|
157 | + return Responder::getJsonResponse( |
|
158 | + $result, |
|
159 | + $response |
|
160 | + ); |
|
161 | 161 | }); |
162 | 162 | |
163 | 163 | $api->put('/matches/{id}/simulate', function ($request, $response, $args) { |
164 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
165 | - ->where( |
|
166 | - [ |
|
167 | - 'id' => $args['id'] |
|
168 | - ] |
|
169 | - )->first(); |
|
170 | - |
|
171 | - if (!empty($result) && !$result->simulated) { |
|
172 | - //simulate match |
|
173 | - $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
174 | - \App\Lib\DsManager\Models\Orm\Match::complete() |
|
175 | - ->where( |
|
176 | - [ |
|
177 | - 'id' => $args['id'] |
|
178 | - ] |
|
179 | - )->first()->toArray() |
|
180 | - ); |
|
181 | - $matchResult = $match->simulate()->toArray(); |
|
182 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::where( |
|
183 | - [ |
|
184 | - 'id' => $args['id'] |
|
185 | - ] |
|
186 | - )->update( |
|
187 | - \App\Lib\DsManager\Models\Orm\MatchResult::castAttributes($matchResult) |
|
188 | - ); |
|
189 | - if ($result === 1) { |
|
190 | - $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
191 | - ->where( |
|
192 | - [ |
|
193 | - 'id' => $args['id'] |
|
194 | - ] |
|
195 | - )->first(); |
|
196 | - } |
|
197 | - |
|
198 | - } |
|
199 | - return Responder::getJsonResponse( |
|
200 | - $result, |
|
201 | - $response |
|
202 | - ); |
|
164 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
165 | + ->where( |
|
166 | + [ |
|
167 | + 'id' => $args['id'] |
|
168 | + ] |
|
169 | + )->first(); |
|
170 | + |
|
171 | + if (!empty($result) && !$result->simulated) { |
|
172 | + //simulate match |
|
173 | + $match = \App\Lib\DsManager\Models\Match::fromArray( |
|
174 | + \App\Lib\DsManager\Models\Orm\Match::complete() |
|
175 | + ->where( |
|
176 | + [ |
|
177 | + 'id' => $args['id'] |
|
178 | + ] |
|
179 | + )->first()->toArray() |
|
180 | + ); |
|
181 | + $matchResult = $match->simulate()->toArray(); |
|
182 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::where( |
|
183 | + [ |
|
184 | + 'id' => $args['id'] |
|
185 | + ] |
|
186 | + )->update( |
|
187 | + \App\Lib\DsManager\Models\Orm\MatchResult::castAttributes($matchResult) |
|
188 | + ); |
|
189 | + if ($result === 1) { |
|
190 | + $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
|
191 | + ->where( |
|
192 | + [ |
|
193 | + 'id' => $args['id'] |
|
194 | + ] |
|
195 | + )->first(); |
|
196 | + } |
|
197 | + |
|
198 | + } |
|
199 | + return Responder::getJsonResponse( |
|
200 | + $result, |
|
201 | + $response |
|
202 | + ); |
|
203 | 203 | }); |
204 | 204 | $api->run(); |
205 | 205 | \ No newline at end of file |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | $c = new \Slim\Container($configuration); |
18 | 18 | $api = new \Slim\App($c); |
19 | 19 | |
20 | -$api->get('/ping', function ($request, $response, $args) { |
|
20 | +$api->get('/ping', function($request, $response, $args) { |
|
21 | 21 | $jsonResp = json_encode( |
22 | 22 | [ |
23 | 23 | "status" => "service up", |
@@ -28,34 +28,34 @@ discard block |
||
28 | 28 | return Responder::getJsonResponse($jsonResp, $response); |
29 | 29 | }); |
30 | 30 | |
31 | -$api->get('/players', function ($request, $response, $args) { |
|
31 | +$api->get('/players', function($request, $response, $args) { |
|
32 | 32 | $json = json_encode(Player::all()); |
33 | 33 | return Responder::getJsonResponse($json, $response); |
34 | 34 | }); |
35 | 35 | |
36 | 36 | |
37 | -$api->get('/players/{id}', function ($request, $response, $args) { |
|
37 | +$api->get('/players/{id}', function($request, $response, $args) { |
|
38 | 38 | return Responder::getJsonResponse( |
39 | 39 | Player::findOrFail($args['id']), |
40 | 40 | $response |
41 | 41 | ); |
42 | 42 | }); |
43 | 43 | |
44 | -$api->get('/coaches', function ($request, $response, $args) { |
|
44 | +$api->get('/coaches', function($request, $response, $args) { |
|
45 | 45 | return Responder::getJsonResponse( |
46 | 46 | Coach::all(), |
47 | 47 | $response |
48 | 48 | ); |
49 | 49 | }); |
50 | 50 | |
51 | -$api->get('/teams', function ($request, $response, $args) { |
|
51 | +$api->get('/teams', function($request, $response, $args) { |
|
52 | 52 | return Responder::getJsonResponse( |
53 | 53 | Team::all(), |
54 | 54 | $response |
55 | 55 | ); |
56 | 56 | }); |
57 | 57 | |
58 | -$api->get('/teams/{id}', function ($request, $response, $args) { |
|
58 | +$api->get('/teams/{id}', function($request, $response, $args) { |
|
59 | 59 | return Responder::getJsonResponse( |
60 | 60 | Team::with( |
61 | 61 | 'roster', |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | ); |
70 | 70 | }); |
71 | 71 | |
72 | -$api->get('/teams/{id}/players', function ($request, $response, $args) { |
|
72 | +$api->get('/teams/{id}/players', function($request, $response, $args) { |
|
73 | 73 | return Responder::getJsonResponse( |
74 | 74 | Team::with( |
75 | 75 | 'roster' |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | ); |
83 | 83 | }); |
84 | 84 | |
85 | -$api->get('/teams/{id}/players/{playerId}', function ($request, $response, $args) { |
|
85 | +$api->get('/teams/{id}/players/{playerId}', function($request, $response, $args) { |
|
86 | 86 | return Responder::getJsonResponse( |
87 | 87 | Player::where( |
88 | 88 | [ |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | ); |
95 | 95 | }); |
96 | 96 | |
97 | -$api->get('/teams/{id}/coach', function ($request, $response, $args) { |
|
97 | +$api->get('/teams/{id}/coach', function($request, $response, $args) { |
|
98 | 98 | return Responder::getJsonResponse( |
99 | 99 | Team::with( |
100 | 100 | 'coach' |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | ); |
108 | 108 | }); |
109 | 109 | |
110 | -$api->get('/matches', function ($request, $response, $args) { |
|
110 | +$api->get('/matches', function($request, $response, $args) { |
|
111 | 111 | return Responder::getJsonResponse( |
112 | 112 | \App\Lib\DsManager\Models\Orm\Match::with( |
113 | 113 | 'homeTeam', |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | ); |
118 | 118 | }); |
119 | 119 | |
120 | -$api->post('/matches', function ($request, $response, $args) { |
|
120 | +$api->post('/matches', function($request, $response, $args) { |
|
121 | 121 | $json = $request->getBody(); |
122 | 122 | $json = json_decode($json, true); |
123 | 123 | return Responder::getJsonResponse( |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | ); |
129 | 129 | }); |
130 | 130 | |
131 | -$api->get('/matches/{id}', function ($request, $response, $args) { |
|
131 | +$api->get('/matches/{id}', function($request, $response, $args) { |
|
132 | 132 | return Responder::getJsonResponse( |
133 | 133 | \App\Lib\DsManager\Models\Orm\Match::with( |
134 | 134 | 'homeTeam', |
@@ -146,7 +146,7 @@ discard block |
||
146 | 146 | ); |
147 | 147 | }); |
148 | 148 | |
149 | -$api->get('/matches/{id}/result', function ($request, $response, $args) { |
|
149 | +$api->get('/matches/{id}/result', function($request, $response, $args) { |
|
150 | 150 | $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
151 | 151 | ->where( |
152 | 152 | [ |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | ); |
161 | 161 | }); |
162 | 162 | |
163 | -$api->put('/matches/{id}/simulate', function ($request, $response, $args) { |
|
163 | +$api->put('/matches/{id}/simulate', function($request, $response, $args) { |
|
164 | 164 | $result = \App\Lib\DsManager\Models\Orm\MatchResult::complete() |
165 | 165 | ->where( |
166 | 166 | [ |