예제 #1
0
        $response->json(Result::error('Demand Creation Failed.'));
    }
});
$this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) {
    $id = $request->param('id');
    $result = Demands::getDemand($id);
    if ($result) {
        $response->json(Result::success('', $result));
    } else {
        $response->json(Result::error('Demand not found'));
    }
});
$this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) {
    $id = $request->param('id');
    $data = json_decode($request->body());
    $result = Demands::updateDemand($id, $data);
    if ($result > 0) {
        $response->json(Result::success('Demand Updated.'));
    } elseif ($result === 0) {
        $response->json(Result::success('Demand not Updated.'));
    } else {
        $response->json(Result::error('Demand not found'));
    }
});
$this->respond(['GET', 'POST'], '/delete/[:id]', function ($request, $response, $service, $app) {
    $id = $request->param('id');
    $result = Demands::deleteDemand($id);
    if ($result > 0) {
        $response->json(Result::success('Demand Deleted.'));
    } else {
        $response->json(Result::error('Demand not Deleted'));