<?php

use \Slim\Http\Request as Request;
use \Slim\Http\Response as Response;
use App\Model\Plan;

$app->get('/planes[/{id}]', function (Request $request, Response $response, $args) {
    if (isset($args['id'])){
        $result = Plan::find($args['id']);
        $response->getBody()->write(Plan::toJSON($result));
    }else{
        try {
            $objects = Plan::all();
        } catch (\Throwable $th) {
            $objects = array();
        }
        $response->getBody()->write(Plan::toJSON($objects));
    }
    return $response;
});
