Exemple #1
0
    def edit(date, time, pickup, dropoff, driver_id, price, status, ride_id):
        """
        A method to edit a ride's details.
        :param date: A string, the date the ride is to be taken.
        :param time: A string, the time the ride is to start.
        :param pickup: A string, the place where the ride starts.
        :param dropoff: A string, the destination of the ride.
        :param driver_id: An int, the unique identifier of the driver of the ride.
        :param price: A string, the price of the ride.
        :param status: A string, the status of the ride.
        :param ride_id: An int, the unique identifier of the ride.
        :return: Http Response
        """
        if status in Ride.STATUS_OPTIONS:
            car = User.get_car(driver_id)
            car_capacity = car['capacity']

            connection = connectDB()
            cursor = connection.cursor(
                cursor_factory=psycopg2.extras.DictCursor)
            Ride.abort_if_ride_offer_doesnt_exist(ride_id)
            try:
                cursor.execute(
                    """UPDATE ride SET 
                        date = %s,
                        time = %s,
                        pickup = %s,
                        dropoff = %s,
                        capacity = %s,
                        driver_id = %s,
                        price = %s,
                        status = %s
                    WHERE id = %s;""",
                    (date, time, pickup, dropoff, car_capacity, driver_id,
                     price, status, ride_id))
                connection.commit()
            except (Exception, psycopg2.DatabaseError) as error:
                connection.rollback()
                return {'status': 'failed', 'data': error}, 500
            cursor.close()
            connection.close()
            return {
                'status': 'success',
                'data': 'Ride offer successfully updated'
            }, 200
        return {
            'status': 'failed',
            'message': 'You entered an invalid ride status'
        }, 404
Exemple #2
0
    def __init__(self,
                 date,
                 time,
                 pickup,
                 dropoff,
                 driver_id,
                 price,
                 status=STATUS_IN_OFFER):
        car = User.get_car(driver_id)
        car_capacity = car['capacity']

        self.date = date
        self.time = time
        self.pickup = pickup
        self.dropoff = dropoff
        self.capacity = car_capacity
        self.seats_available = car_capacity
        self.driver_id = driver_id
        self.price = price
        self.status = status