示例#1
0
def return_():
    bookingAction = BookingAction(request.form['booking_id'], "returned")
    db.session.add(bookingAction)
    booking = Booking.query.get(request.form['booking_id'])
    carLocation = CarLocation(booking.car_id, "Ho Chi Minh City")
    db.session.add(carLocation)
    db.session.commit()
    return '', 200
示例#2
0
def api_login_by_facial_recognition():
    user = User.query.filter_by(username=request.form['username']).first()
    if user:
        car = Car.query.filter_by(id=request.form['car_id']).first()
        if car.booked and car.bookings[-1].user_id == user.id:
            bookingAction = BookingAction(car.bookings[-1].id, "unlocked")
            db.session.add(bookingAction)
            db.session.commit()
            return user.serialize(), 200
    else:
        return '{}', 401
示例#3
0
def book():
    car = Car.query.filter_by(id = request.form['car_id']).first()
    if car:
        user_id = current_user.id
    booking = Booking(user_id, car.id, request.form['duration'])
    db.session.add(booking)
    db.session.commit()
    bookingAction = BookingAction(booking.id, "created")
    db.session.add(bookingAction)
    db.session.commit()
    return '', 200
示例#4
0
def book():
    car = Car.query.filter_by(id=request.form['car_id']).first()
    if car:
        user_id = request.form['user_id']
    booking = Booking(user_id, car.id, request.form['duration'])
    db.session.add(booking)
    db.session.commit()
    bookingAction = BookingAction(booking.id, "created")
    db.session.add(bookingAction)
    db.session.commit()
    add_event_for_calendar(booking, bookingAction)
    return 'success', 200
示例#5
0
def unlock():
    """ This function allow user to unlock (POST) a car

        a booking action record for unlock is created

        :<json int booking_id: id of a booking record

        :status 200: car unlocked
    """
    bookingAction = BookingAction(request.form['booking_id'], "unlocked")
    db.session.add(bookingAction)
    db.session.commit()
    return '', 200
示例#6
0
def cancel():
    """ API for cancelling (POST) a booking
        
        a booking action record is created

        :param int booking_id: id of a booking record

        :status 200: book canceled
    """
    bookingAction = BookingAction(request.form['booking_id'], "cancelled")
    db.session.add(bookingAction)
    db.session.commit()
    return 'success', 200
示例#7
0
def unlock():
    """ API for unlocking (POST) a car

        a booking action record is created

        :param int booking_id: id of a booking record

        :status 200: book created
    """
    bookingAction = BookingAction(request.form['booking_id'], "unlocked")
    db.session.add(bookingAction)
    db.session.commit()
    return 'success', 200
示例#8
0
def api_logout():
    car = Car.query.filter_by(id=request.form['car_id']).first()
    bookingAction = BookingAction(car.bookings[-1].id, "returned")
    db.session.add(bookingAction)
    booking = Booking.query.get(car.bookings[-1].id)
    current_location_coordinate = get_current_location_coordinate()
    current_location_name = get_current_location_name(
        **current_location_coordinate)
    carLocation = CarLocation(booking.car_id,
                              long=current_location_coordinate['lng'],
                              lat=current_location_coordinate['lat'],
                              location=current_location_name)
    db.session.add(carLocation)
    db.session.commit()
    return '{}', 200
示例#9
0
def cancel():
    """ This function allow user to cancel (POST) a booking
        
        a booking action record for cancel booking is created

        :<json int booking_id: id of a booking record

        :status 200: book canceled
    """
    bookingAction = BookingAction(request.form['booking_id'], "cancelled")
    booking = Booking.query.filter_by(id=request.form['booking_id']).first()
    if booking.calendar_id:
        delete_event_calendar(booking.calendar_id)
    db.session.add(bookingAction)
    db.session.commit()
    return '', 200
示例#10
0
def return_():
    """ API for user to return (POST) a car

        a booking action record is created

        :param int booking_id: id of a booking record

        :status 200: return succeed 
    """
    bookingAction = BookingAction(request.form['booking_id'], "returned")
    db.session.add(bookingAction)
    booking = Booking.query.get(request.form['booking_id'])
    carLocation = CarLocation(booking.car_id, "Ho Chi Minh City")
    db.session.add(carLocation)
    db.session.commit()
    return 'success', 200
示例#11
0
def api_login_by_credentials():
    """ This function allow user to unlock car by using their account

    :param str username: user name of the user
    :param str password: password of the user

    :status 200: login success
    :status 401: login failed
    """

    user = User.query.filter_by(username=request.form['username']).first()
    if user and check_password_hash(user.password, request.form['password']):
        car = Car.query.filter_by(id=request.form['car_id']).first()
        if car.booked and car.bookings[-1].user_id == user.id:
            bookingAction = BookingAction(car.bookings[-1].id, "unlocked")
            db.session.add(bookingAction)
            db.session.commit()
            return user.serialize(), 200
        return '{}', 401
    else:
        return '{}', 401
示例#12
0
def return_():
    """ This function allow user to return (POST) a car

        a booking action record is created

        :<json int booking_id: id of a booking record

        :status 200: return succeed 
    """
    bookingAction = BookingAction(request.form['booking_id'], "returned")
    db.session.add(bookingAction)
    booking = Booking.query.get(request.form['booking_id'])
    current_location_coordinate = get_current_location_coordinate()
    current_location_name = get_current_location_name(
        **current_location_coordinate)
    carLocation = CarLocation(booking.car_id,
                              long=current_location_coordinate['lng'],
                              lat=current_location_coordinate['lat'],
                              location=current_location_name)
    db.session.add(carLocation)
    db.session.commit()
    return '', 200
示例#13
0
def book():
    """ This function allow user to book (POST) a car

        When user book a car, a booking record and booking action is created 

        :<json int car_id: id of a existing car
        :<json int duration: book duration (hours)

        :status 200: book created
    """
    car = Car.query.filter_by(id=request.form['car_id']).first()
    if car:
        user_id = current_user.id
    booking = Booking(user_id, car.id, request.form['duration'])
    db.session.add(booking)
    db.session.commit()
    bookingAction = BookingAction(booking.id, "created")
    db.session.add(bookingAction)
    db.session.commit()
    event = add_event_for_calendar(booking, bookingAction)
    booking.calendar_api = event['id']
    db.session.commit()
    return '', 200
示例#14
0
def cancel():
    bookingAction = BookingAction(request.form['booking_id'], "cancelled")
    db.session.add(bookingAction)
    db.session.commit()
    return '', 200
示例#15
0
def unlock():
    bookingAction = BookingAction(request.form['booking_id'], "unlocked")
    db.session.add(bookingAction)
    db.session.commit()
    return '', 200