Exemple #1
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')}
Exemple #2
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')}
Exemple #3
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"}
Exemple #4
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')}