def put(self, request): body_data = decode_body(request) update_geo(body_data, request.user) return Response({ "status": "success", "msg": "updated geo position", })
def post(self, request): body_data = decode_body(request) long, lat, city = update_geo(body_data, request.user) drivers = ds.find_nearest(city, long, lat) ds.add_geo(city, long, lat, request.user) ds.set_driver_seats(request.user, 4) return Response({"status": "success", "msg": "you are in queue we are searching for rider near you"})
def post(self, request, format=None): body_data = decode_body(request) if not body_data.get('to_long') or not body_data.get('to_lat') or \ not body_data.get('city') or not body_data.get('seats'): return Response({"status": "fail", "msg": "to_lang, to_lat, seats, city params require"}) if int(body_data.get('seats')) > 2: return Response({"status": "fail", "msg": "for pool only 2 seats are allowed"}) long, lat, city = update_geo(body_data, request.user) to_long = body_data.get('to_long') to_lat = body_data.get('to_lat') drivers = ds.find_nearest(city, long, lat) if len(drivers) == 0: return Response({"status": "fail", "error": "no driver near you"}) for i in drivers: seats = int(ds.get_driver_seats(i[0]) or 0) if seats >= int(body_data.get('seats')): distance = ds.find_distance(city, i[0], to_long, to_lat) serial = { "from_long_position": long, "from_lat_position": lat, "to_long_position": to_long, "to_lat_position": to_lat, "status": "start", "distance": distance, "fair": get_fair(distance, pool=True), "driver": i[0], "rider": request.user, "seats": int(body_data.get('seats')) } booking = BookingSerializer(data=serial) if booking.is_valid(raise_exception=ValueError): booking = booking.create(serial) if booking and seats - int(body_data.get('seats')) == 0: ds.del_geo(city, i[0]) ds.del_driver_from_pool(i[0]) elif booking and seats - int(body_data.get('seats')) > 0: ds.add_geo(booking.driver.city, booking.to_long_position, booking.to_lat_position, booking.driver) ds.set_driver_seats(i[0], seats - int(body_data.get('seats'))) return Response( { "status": "success", "msg": "Driver is on the way", "driver": i[0], "fair": booking.fair, "distance": booking.distance }) return Response({"status": "fail", "error": "no driver near you"})
def post(self, request): body_data = decode_body(request) err, booking = end_ride_rider(request.user) long, lat, city = update_geo(body_data, request.user) current_seats = ds.get_driver_seats(request.user) ds.add_geo(city, long, lat, request.user) ds.set_driver_seats(request.user, int(current_seats or 0) + booking.seats) if not booking: return Response({ "status": "fail", "error": err }) return Response({ "status": "success", "msg": "Thank You for choosing us", "fair": booking.fair })
def post(self, request): body_data = decode_body(request) if not body_data.get('to_long') and not body_data.get('to_lat'): return Response({"status": "fail", "error": "no destination specified"}) long, lat, city = update_geo(body_data, request.user) to_long = body_data.get('to_long') to_lat = body_data.get('to_lat') drivers = ds.find_nearest(city, long, lat) if len(drivers) == 0: return Response({"status": "fail", "error": "no driver near you"}) for i in drivers: distance = ds.find_distance(city, i[0], to_long, to_lat) if int(ds.get_driver_seats(i[0]) or 0) == 4: serial = { "from_long_position": long, "from_lat_position": lat, "to_long_position": to_long, "to_lat_position": to_lat, "status": "start", "driver": i[0], "rider": request.user, "distance": distance, "seats": 4, "fair": get_fair(distance) } booking = BookingSerializer(data=serial) if booking.is_valid(raise_exception=ValueError): booking = booking.create(serial) ds.del_driver_from_pool(i[0]) selected_driver = i[0] return Response({ "status": "success", "msg": "Driver is on the way", "driver": selected_driver, "fair": booking.fair }) return Response({"status": "fail", "error": "no driver near you"})
def put(self, request): body_data = decode_body(request) long, lat, city = update_geo(body_data, request.user) if len(ds.match(city, request.user)[1]) != 0: ds.add_geo(city, long, lat, request.user) return Response({"status": "success", "msg": "location updated"})