| 1 | <?php |
||
| 2 | |||
| 3 | namespace Faxity\Weather; |
||
| 4 | |||
| 5 | use Anax\Commons\ContainerInjectableInterface; |
||
| 6 | use Anax\Commons\ContainerInjectableTrait; |
||
| 7 | |||
| 8 | /** |
||
| 9 | * Controller for the /ip-api routes |
||
| 10 | */ |
||
| 11 | class APIController implements ContainerInjectableInterface |
||
| 12 | { |
||
| 13 | use ContainerInjectableTrait; |
||
| 14 | |||
| 15 | |||
| 16 | /** |
||
| 17 | * Handles / for the controller |
||
| 18 | * |
||
| 19 | * @return array |
||
| 20 | */ |
||
| 21 | 2 | public function indexActionPost() : array |
|
| 22 | { |
||
| 23 | 2 | $location = $this->di->request->getPost("location", ""); |
|
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
| 24 | 2 | $pastMonth = $this->di->request->getPost("past-month") !== null; |
|
| 25 | 2 | $status = 200; |
|
| 26 | |||
| 27 | try { |
||
| 28 | 2 | $res = $this->di->weather->forecast($location, $pastMonth); |
|
|
0 ignored issues
–
show
|
|||
| 29 | 1 | } catch (\Exception $ex) { |
|
| 30 | 1 | $status = 400; |
|
| 31 | 1 | $message = $ex->getMessage(); |
|
| 32 | 1 | $res = [ "status" => $status, "message" => $message ]; |
|
| 33 | } |
||
| 34 | |||
| 35 | 2 | return [ (array) $res, $status ]; |
|
| 36 | } |
||
| 37 | } |
||
| 38 |