Ejemplo n.º 1
0
    $app->group('/groups', function () use($app, $model) {
        $app->get('/', function ($req, $res, $arg) use($model) {
            $res->getBody()->write(json_encode($model->showGroups()));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
        $app->get('/{gid:[0-9]+}', function ($req, $res, $arg) use($model) {
            $res->getBody()->write(json_encode($model->showGroup($arg['gid'])));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
        $app->post('/', function ($req, $res, $arg) use($model) {
            $status = $model->createGroup($req->getParams());
            $res->getBody()->write(json_encode(array('status' => $status == 0 ? false : true)));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
        $app->put('/{gid:[0-9]+}', function ($req, $res, $arg) use($model) {
            $data = json_decode($req->getBody(), true);
            $data['id'] = $arg['gid'];
            $res->getBody()->write(json_encode(array('status' => $model->editGroup($data))));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
        $app->delete('/{gid:[0-9]+}', function ($req, $res, $arg) use($model) {
            $res->getBody()->write(json_encode(array('status' => $model->deleteGroup($arg['gid']))));
            $res = $res->withHeader('Content-type', 'application/json');
            $res = $res->withStatus(200);
        });
    });
});