Example #1
0
    def save(self, request):
        newBook = Booking()
        newBook.customer = request.user
        newBook.payment_type = request.POST.get("payment_type")
        newBook.price = request.POST.get("price")
        newBook.total_distance = request.POST.get("total_distance")
        newBook.save()
        self.validated_data['book_id'] = newBook.id

        pickupAddress = Address()
        pickupAddress.title = request.POST.get("pickup_address_title")
        pickupAddress.description = request.POST.get(
            "pickup_address_description")
        pickupAddress.longitude = request.POST.get("pickup_address_longitude")
        pickupAddress.latitude = request.POST.get("pickup_address_latitude")
        pickupAddress.is_pickup_loc = True
        pickupAddress.booking = newBook
        pickupAddress.save()

        arrivalAddress = Address()
        arrivalAddress.title = request.POST.get("arrival_address_title")
        arrivalAddress.description = request.POST.get(
            "arrival_address_description")
        arrivalAddress.longitude = request.POST.get(
            "arrival_address_longitude")
        arrivalAddress.latitude = request.POST.get("arrival_address_latitude")
        arrivalAddress.is_arrival_loc = True
        arrivalAddress.booking = newBook
        arrivalAddress.save()

        #  find nearest userInfo
        # nearestDriverUserInfo = findNearestDriver(latitude=pickupAddress.latitude , longitude=pickupAddress.longitude , filterMaxDistance=10000)
        # newBook.driver = nearestDriverUserInfo.user
        return newBook
Example #2
0
 def create_booking(self, model: CreateBookingDto):
     booking = Booking()
     booking.booking_reference = model.booking_reference
     booking.flight_id = model.flight_id
     booking.take_off_point = model.take_off_point
     booking.price = model.price
     booking.take_off_time = model.take_off_time
     booking.destination = model.destination
     booking.flight_class = model.flight_class
     booking.name = model.name
     booking.phone = model.phone
     booking.email = model.email
     booking.address = model.address
     booking.save()
Example #3
0
def booking(request, booking_id):
    # GET information about the status of a device.  Some way of securing this so only the app can
    # access it will eventually be needed
    if request.method == 'GET':
        try:
            booking = Booking.objects.get(pk=booking_id)
            return JsonResponse(booking.toJSON())
        except Booking.DoesNotExist:
            return JsonResponse({}, status=404)
        # if(booking):
        #     return JsonResponse(booking.toJSON())
        # else:
        #     return JsonResponse({}, status=404)

    # Make request to turn on a device.  A function should respond back with a value from the arduino
    # indicating success and this can be passed back to app
    elif request.method == 'POST':
        body_unicode = request.body.decode('utf-8')
        body = json.loads(body_unicode)
        StartTime = body.get('StartTime')
        EndTime = body.get('EndTime')
        IDUser = body.get('IDUser')

        if not StartTime:
            return JsonResponse({"REASON": "Invalid StartTime provided"},
                                status=400)
        elif not EndTime:
            return JsonResponse({"REASON": "Invalid EndTime provided"},
                                status=400)
        elif not IDUser:
            return JsonResponse({"REASON": "Invalid IDUser provided"},
                                status=400)
        else:
            # this is our "happy path", once everything checks out, we send call to turn on device
            # Add your code to turn on the device here and the respond back.
            booking = Booking(IDUser=IDUser,
                              StartTime=StartTime,
                              EndTime=EndTime)
            resp = booking.save()
            print(resp)
            return JsonResponse(booking.toJSON())