def post(self): data = request.get_json(force=True) #res = trips_plan_schema.load(json.loads(json.dumps(data))) print(data) if not data: return {'message': 'No data provided'}, 400 new_trip = TripPlanModel(vehicle_type=data['vehicle_type'], no_of_passengers=data['no_of_passengers'], date_from=data['date_from'], date_to=data['date_to'], pickup_time=data['pickup_time'], pickup_loc=data['start_location'], waypoint=data['waypoint'], ac_condition=data['ac_condition'], destination=data['destination'], passenger_id=data['passenger_id'], description=data['trip_description']) try: new_trip.save_to_db() return {'trip_id': new_trip.trip_id} except Exception as e: return {'message': 'Something went wrong', 'error': e}, 500
def owner_suitsfor_trip(self, owId): area = OwnerModel().get_area(owId) trip_by_area = TripPlanModel().trip_detailsbyArea(area) trip_plan_json = trips_plan_schema.dump(trip_by_area) return_data = [] for trip in trip_plan_json: trip_details = self.get_tripDetails(trip['trip_id']) for details in trip_details: if (VehicleModel().driver_has_vehicle_byLoad( owId, details['no_of_passengers']) or VehicleModel().driver_has_vehicle_byAC( owId, details['ac_condition']) and VehicleModel().driver_has_vehicle_byType( owId, details['vehicle_type'])): return_data.append({ 'is_ok': True, 'trip': trip['trip_id'] }) break else: return_data.append({ 'is_ok': False, 'trip': trip['trip_id'] }) break return return_data
def get(self, ow_id): trips_detail = [] print('SINGLE TRIP', trip_plan_schema.dump(TripPlanModel.findtrip_by_id(2))) if OwnerModel().is_owner(ow_id): result = self.owner_suitsfor_trip(ow_id) print('Results', result) for item in result: if item['is_ok']: #trips_detail.append(trips_plan_schema.dump(TripPlanModel().find_by_trip_id(item['trip']))) trips_detail.append( trip_plan_schema.dump( TripPlanModel.findtrip_by_id(item['trip']))) print(trips_detail) return trips_detail else: return {'message': 'No trips for you !'}
def get(self, drId): if TripStatusModel().trips_available_for_driver(drId): trip_id = TripStatusModel().trip_id_for_driver(drId) print('tripId', trip_id) trips_detail = trips_plan_schema.dump( TripPlanModel().find_by_trip_id(trip_id)) print(trips_detail) return { 'trip_status_id': TripStatusModel().tripstatus_for_driver(drId), 'trips_detail': trips_detail } else: print('else') return {'message': 'no trips for you !'}
def get_tripDetails(self, trip_id): return trips_plan_schema.dump(TripPlanModel().find_by_trip_id(trip_id))
def get(self, trip_id): res = trips_plan_schema.dump(TripPlanModel().find_by_trip_id(trip_id)) return {'trip_plan': res}
def get(self): res = trips_plan_schema.dump(TripPlanModel().return_all()) return {'trip_plans': res}