示例#1
0
 /**
 * Url:
 * /public/api/v1.0/update/bus/destination/{dropping_id}
 * 
 * Payload:
    {
        "params": {
            "buses_id": 27,
            "bus_departure_points_id": 5,
            "dropping_point": "Tada",
            "dropping_time": "9am",
            "price": "1003"
        }
    }
 */
 public function updateDroppingDetails(Request $request)
 {
     $data = Input::json()->all();
     $response = $this->response;
     $validateAndHandleError = new ValidateAndHandleError();
     if (!Auth::user()->id) {
         return $validateAndHandleError->invalidUser();
     }
     if (!$request->route('dropping_id')) {
         return $response->errorResponse("dropping_id_not_exist");
     }
     $dropping_id = $request->route('dropping_id');
     if (!isset($data) || !isset($data['params']) || !isset($data['params']['buses_id']) || !isset($data['params']['bus_departure_points_id']) || !isset($data['params']['dropping_point']) || !isset($data['params']['place_id']) || !isset($data['params']['dropping_time']) || !isset($data['params']['price'])) {
         return $response->errorResponse('invalid_params');
         //                return $validateAndHandleError->errorIdentifier("invalid_params");
     }
     $buses_id = $data['params']['buses_id'];
     $bus_departure_points_id = $data['params']['bus_departure_points_id'];
     $dropping_point = $data['params']['dropping_point'];
     $dropping_time = $data['params']['dropping_time'];
     $place_id = $data['params']['place_id'];
     $price = $data['params']['price'];
     /* Null validation */
     $validateNullData = array("buses_id" => $buses_id, "bus_departure_points_id" => $bus_departure_points_id, "dropping_point" => $dropping_point, "dropping_time" => $dropping_time, "price" => $price, "place_id" => $place_id);
     $nullValidator = $validateAndHandleError->multiValidator($validateNullData, "string");
     if ($nullValidator != "success") {
         return $nullValidator;
     }
     /* Bus id is number or not */
     $validateBusId = $validateAndHandleError->multiValidator(['buses_id' => $buses_id, 'dropping_id_not_number' => $dropping_id, 'place_id' => $place_id, 'departure_id_not_number' => $bus_departure_points_id], "number");
     if ($validateBusId != "success") {
         return $validateBusId;
     }
     $place = Place::where('id', $place_id)->get()[0]->place;
     if ($place != $dropping_point) {
         return $response->errorResponse('to_place_mismatch');
         //                return $validateAndHandleError->errorIdentifier("to_place_mismatch");
     }
     /* Validate dropping id present in db or not */
     $check_dropping_id = BusDroppingPoint::where('id', $dropping_id)->get();
     if (count($check_dropping_id) <= 0) {
         return $response->errorResponse("dropping_details_not_available");
     }
     /* for this dropping id check bus_id and departure id is matching or not */
     if ($check_dropping_id[0]->buses_id != $buses_id || $check_dropping_id[0]->bus_departure_points_id != $bus_departure_points_id) {
         return $response->errorResponse("bus_id_and_departure_id_mismatch");
     }
     /* Bus id exist or not */
     $check_bus_availability = Bus::where('id', $buses_id)->get();
     if (count($check_bus_availability) <= 0) {
         return $response->errorResponse("bus_details_not_available");
     }
     /* Departure id exist or not */
     $prev_departure_details = BusDeparturePoint::where('id', $bus_departure_points_id)->get();
     if (count($prev_departure_details) <= 0) {
         return $response->errorResponse('bus_departure_details_does_not_exist');
         //                return $validateAndHandleError->errorIdentifier("bus_departure_details_does_not_exist");
     }
     /* bus id passed through param should be equal with bus id of db */
     if ($prev_departure_details[0]->buses_id != $buses_id) {
         return $response->errorResponse('invalid_departure_details');
         //                return $validateAndHandleError->errorIdentifier("invalid_departure_details");
     }
     $user_id = Auth::user()->id;
     $bus_owners_id = $check_bus_availability[0]->bus_owners_id;
     /* $user_id_temp is used to check whether the details are accessible or not */
     $user_id_temp = BusOwner::where('id', $bus_owners_id)->get()[0]->user_id;
     $user_type = $validateAndHandleError->userIdentifier($user_id);
     /* details are only accessible by admin and bus owner */
     if ($user_type == "customer" || $user_type == "dealer" || $user_type == "unknown" || $user_type == "bus_owner" && $user_id_temp != $user_id) {
         return $response->errorResponse("details_not_accessible");
     }
     $is_dropping_details_updated = BusDroppingPoint::where('id', $dropping_id)->where('buses_id', $buses_id)->where('bus_departure_points_id', $bus_departure_points_id)->update(['dropping_point' => $dropping_point, 'dropping_time' => $dropping_time, 'price' => $price]);
     $info = array('bus_dropping_id' => $dropping_id, 'bus_id' => $buses_id, 'bus_owners_id' => $bus_owners_id, 'departure_id' => $bus_departure_points_id, 'dropping_point' => $dropping_point, 'dropping_time' => $dropping_time, 'price' => $price);
     if ($is_dropping_details_updated == 1) {
         return $response->successResponse(200, "Bus dropping details has been updated successully", $info);
     }
     return $response->errorResponse("update_unsuccessfull");
 }
示例#2
0
 public function errorResponse($error, $message = null)
 {
     $validateAndHandleError = new ValidateAndHandleError();
     $response = Response::json(array('error' => true, 'info' => $validateAndHandleError->errorIdentifier($error)));
     return $response;
 }