/** * check bus post current position iteration. current iteration is every 1,5 minutes * so, if iteration is 160 (40 mins of total current location post request), system will make request to google maps * api (directions) to avoid over quota * * @return \Illuminate\Http\JsonResponse */ public function checkBusIteration() { $busOperationModel = new BusOperation(); $busOperation = $busOperationModel->where('plat_nomor', '=', $this->plat_nomor)->get()->toArray(); if (sizeof($busOperation) > 0 && $busOperation != null) { //if there is a record about that bus, we will take action if ($busOperation[0]['iterasi_arrival_check'] >= 4) { $busOperationModel->where('plat_nomor', '=', $this->plat_nomor)->update(['iterasi_arrival_check' => 0]); return true; } else { $busOperationModel->where('plat_nomor', '=', $this->plat_nomor)->update(['iterasi_arrival_check' => $busOperation[0]['iterasi_arrival_check'] + 1]); return false; } } else { //if there is no record, exception will be thrown throw new Exception("Bus Not Found"); } }
/** * delete bus operation from database based on plat nomor * * @param $plat_nomor * @return \Illuminate\Http\JsonResponse */ public function deleteBusOperation($plat_nomor) { $busOperationModel = new BusOperation(); $response = array(); try { $busOperationModel->where('plat_nomor', '=', $plat_nomor)->delete(); $response['code'] = 200; $response['data']['msg'] = 'bus has been successfully deleted from database'; } catch (\Exception $e) { $response['code'] = 500; $response['data']['msg'] = 'failed to delete bus, please make sure that plat nomor is correct'; } header("Access-Control-Allow-Origin: *"); return response()->json($response); }