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