def get(request, connection): try: __user = request['user'] except KeyError: raise HTTP_400_Exception('Missing required field : user') try: __friend_status = request['status'] except KeyError: raise HTTP_400_Exception('Missing required field : status') if __friend_status == 'friends': __link = query_strings.search_friends.format(__user) elif __friend_status == 'responses': __link = query_strings.search_pending_requests.format(__user) elif __friend_status == 'requests': __link = query_strings.search_requests_sent.format(__user) else: raise HTTP_400_Exception('Invalid friend status') with connection.cursor() as cur: try: cur.execute(__link) li = cur.fetchall() except pymysql.err.IntegrityError: raise HTTP_204_Exception('User not found') new_list = [] for item in li: usr = dict() usr['user_id'] = item[0] usr['display_name'] = item[1] usr['profile_pic'] = item[2] usr['email'] = item[3] usr['first_name'] = item[4] usr['last_name'] = item[5] usr['mission_curator'] = item[6] usr['birthday'] = item[7] usr['location'] = item[8] new_list.append(usr) body = Body() body.addParameter('data', new_list) return body
def get(request, query_str_param, connection): try: name = request['name'] searchQuery = query_strings.search_for_mission.format(name) except KeyError: searchQuery = query_strings.search_all_missions with connection.cursor() as cur: try: cur.execute(searchQuery) missions = cur.fetchall() except pymysql.err.IntegrityError: raise HTTP_204_Exception('User not found') body = Body() body.addParameter('missions', missions) body.addParameter('message', 'missions.get has been called') return body
def put(request, query_str_param, connection): body = Body() body.addParameter('message', 'missions.put has been called') return body
def delete(request, query_str_param, connection): body = Body() body.addParameter('message', 'events.delete has been called') return body
def put(request, connection): body = Body() body.addParameter('message', 'plan.put has been called') return body
def get(request, connection): body = Body() body.addParameter('message', 'mai.get has been called') return body
def get(request, query_str_param, connection): if query_str_param is None: query_str_param = {} try: email = query_str_param['email'] except KeyError: raise HTTP_400_Exception('Missing required field - email') # query for user in the database user_query = query_strings.search_all_user_details_by_email.format(email) body = Body() with connection.cursor() as cur: cur.execute(user_query) item = cur.fetchone() # add user details if item is not None: body.addParameter('display_name', item[1]) body.addParameter('profile_pic', item[2]) body.addParameter('email', item[3]) body.addParameter('first_name', item[4]) body.addParameter('last_name', item[5]) body.addParameter('mission_curator', False if item[6] == 0 else True) body.addParameter('birthday', item[7]) # add user's address as location if item[8] is not None: # query for location using the location id cur.execute( query_strings.search_all_fields_location.format(item[8])) loc = cur.fetchone() location = dict() location['street'] = loc[1] location['city'] = loc[2] location['state'] = loc[3] location['zip'] = loc[4] location['country'] = loc[5] location['latitude'] = loc[6] location['longitude'] = loc[7] body.addParameter('location', location) else: body.addParameter('location', None) return body