public static function updateRentArea($rentAreaID, $rentAreaData) { global $db; // check if exists if (RentAreas::getRentArea($rentAreaID)) { return $db->update('rentAreas', $rentAreaData, ['id' => $rentAreaID]); } return -1; }
<?php $this->respond(['GET', 'POST'], '/create', function ($request, $response, $service, $app) { $data = json_decode($request->body(), true); $id = RentAreas::createRentArea($data); if ($id > 0) { $response->json(Result::success('RentArea Created.', ['id' => $id])); } else { $response->json(Result::error('RentArea Creation Failed.')); } }); $this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $result = RentAreas::getRentArea($id); if ($result) { $response->json(Result::success('', $result)); } else { $response->json(Result::error('RentArea not found')); } }); $this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) { $id = $request->param('id'); $data = json_decode($request->body()); $result = RentAreas::updateRentArea($id, $data); if ($result > 0) { $response->json(Result::success('RentArea Updated.')); } elseif ($result === 0) { $response->json(Result::success('RentArea not Updated.')); } else { $response->json(Result::error('RentArea not found')); }