Пример #1
0
 def request_ride(self, user, ride_id):
     """Make a ride request."""
     ride = Ride()
     app_user = User()
     connection = self.create_db_connection()
     owner_data = app_user.find_user(connection, user).get('Message')
     owner_id = owner_data[0][0]
     ride = ride.get_ride_by_id(connection, ride_id)
     if not ride.get('Status'):
         return {'Status': False, 'Message': ride.get('Message')}
     ride_data = ride.get('Message')
     ride_owner = ride_data[0]['Owner Id']
     if owner_id == ride_owner:
         return {
             'Status': False,
             "Message": "You cant request your own ride"
         }
     request_data = {
         "Passenger Id": owner_id,
         "Email": user,
         "Ride Id": ride_id
     }
     request = Request(request_data)
     res = request.create_request(connection)
     if res.get('Status'):
         return {'Status': True, 'Message': res.get('Message')}
     return {'Status': False, 'Message': res.get('Message')}
Пример #2
0
 def create_user(self, user_data):
     """Create a user record."""
     connection = self.create_db_connection()
     email = user_data.get('Email')
     password = user_data.get('Password')
     confirm_password = user_data.get('Confirm Password')
     user_type = user_data.get('Type')
     if self.is_empty(user_type):
         return {'Status': False, "Message": "Type cannot be blank"}
     if user_type.lower() not in ('driver', 'passenger'):
         return {
             'Status': False,
             'Message': 'Type can only be \'driver\' or \'passenger\''
         }
     driver = False
     if user_type == 'driver':
         driver = True
     if self.is_empty(email):
         return {'Status': False, 'Message': 'Email cannot be blank'}
     user_details = {
         "email": email,
         "password": password,
         "confirm_password": confirm_password,
         "user_type": driver
     }
     user = User(user_details)
     res = user.create_user(connection)
     if res.get('Status'):
         return {'Status': True, 'Message': res.get('Message')}
     return {'Status': False, 'Message': res.get('Message')}
Пример #3
0
    def create_ride(self, ride_data):
        """Request models to create ride."""
        user = User()
        connection = self.create_db_connection()
        for key, value in ride_data.items():
            if type(value) == str:
                if self.is_empty(value):
                    return {
                        'Status': False,
                        'Message': '{} is empty'.format(key)
                    }
        owner = ride_data.get('Owner')
        owner_data = user.find_user(connection, owner).get('Message')
        owner_id = owner_data[0][0]
        date = ride_data.get('Date')
        time = ride_data.get('Time')
        identifier = '{}-{}-{}'.format(owner, date, time)
        ride_data.update({'Owner Id': owner_id})
        ride_data.update({'Identifier': identifier})

        resp = self.validate_date(date)
        ride = Ride(ride_data)
        if resp.get('Status'):
            res = ride.create_ride(connection)
            if res.get('Status'):
                return {'Status': True, 'Message': res.get('Message')}
            return {'Status': False, 'Message': res.get('Message')}
        return {"Status": False, "Message": resp.get('Message')}
Пример #4
0
 def verify_user_credentials(self, logins):
     """Verify user credentials to login."""
     user = User()
     email = logins.get('Email')
     password = logins.get('Password')
     if self.is_empty(email):
         return {'Status': False, 'Message': 'Email cannot be blank'}
     connection = self.create_db_connection()
     res = user.find_user(connection, email)
     if res.get('Status'):
         if password == res.get('Message')[0][2]:
             return {'Status': True, "Message": 'Valid Credentials'}
         return {'Status': False, "Message": 'Invalid Credentials'}
     return {'Status': False, 'Message': "Invalid Credentials"}
Пример #5
0
 def drop_all(self):
     """Delete all tables."""
     user = User()
     ride = Ride()
     request = Request()
     connection = self.create_db_connection()
     resp = request.delete_requests_table(connection)
     if resp.get('Status'):
         result = ride.delete_rides_table(connection)
         if result.get('Status'):
             res = user.delete_user_table(connection)
             if res.get('Status'):
                 return {'Status': True, 'Message': 'Deleted all tables'}
             return {'Status': False, 'Message': res.get('Message')}
         return {'Status': False, 'Message': result.get('Message')}
     return {'Status': False, 'Message': resp.get('Message')}
Пример #6
0
    def create_all(self):
        """Create the db with all the tables.

        Args:
            db(dict): database connection information
        """
        user = User()
        ride = Ride()
        request = Request()
        connection = self.create_db_connection()
        res = user.create_user_table(connection)
        if res.get('Status'):
            resp = ride.create_rides_table(connection)
            if resp.get('Status'):
                result = request.create_requests_table(connection)
                if result.get('Status'):
                    return {'Status': True, 'Message': 'All tables created'}
                return {'Status': result.get('Message')}
            return {'Status': False, 'Message': resp.get('Message')}
        return {'Status': False, 'Message': res.get('Message')}
Пример #7
0
 def get_requests(self, ride_id, user):
     """Request rides requests from db."""
     ride = Ride()
     app_user = User()
     request = Request()
     connection = self.create_db_connection()
     owner_data = app_user.find_user(connection, user).get('Message')
     owner_id = owner_data[0][0]
     ride = ride.get_ride_by_id(connection, ride_id)
     if ride.get('Status'):
         ride_data = ride.get('Message')
         ride_owner = ride_data[0]['Owner Id']
         if owner_id == ride_owner:
             requests = request.get_ride_requests(connection, ride_id)
             if requests.get('Status'):
                 return {'Status': True, 'Message': requests.get('Message')}
             return {'Status': False, 'Message': requests.get('Message')}
         return {'Status': False, \
                 'Message': 'You dont have access to that ride'}
     return {'Status': False, 'Message': ride.get('Message')}