Example #1
0
    return new Response($result, 200);
});
// Get admin by id
$app->GET('/admin/{admin_id}', function (Application $app, Request $request, $admin_id) {
    $handler = new AdminHandler();
    $result = $handler->get($admin_id);
    return new Response($result, 200);
});
// Create admin
$app->PUT('/admin', function (Application $app, Request $request) {
    if (!authenticate('1', null)) {
        return new Response('Unauthorized', 401);
    }
    $object = array('username' => $request->get('username'), 'password' => $request->get('password'), 'first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'), 'role_id' => $request->get('role_id'));
    $handler = new AdminHandler();
    $result = $handler->add($object);
    return new Response($result['message'], $result['status_code']);
});
// Update admin
$app->POST('/admin/{admin_id}', function (Application $app, Request $request, $admin_id) {
    if (!authenticate('user', $admin_id)) {
        return new Response('Unauthorized', 401);
    }
    $object = array('admin_id' => $admin_id, 'username' => $request->get('username'), 'first_name' => $request->get('first_name'), 'last_name' => $request->get('last_name'), 'email' => $request->get('email'));
    $handler = new AdminHandler();
    $result = $handler->update($object);
    return new Response($result['message'], $result['status_code']);
});
// Update role
$app->POST('/admin/{admin_id}/role', function (Application $app, Request $request, $admin_id) {
    if (!authenticate('1', null)) {