예제 #1
0
def put(request, connection):

    try:
        __first_user = request['user1']
        __second_user = request['user2']
        __action = request['action']
    except KeyError:
        raise HTTP_400_Exception('Missing required field(s)')

    # __first_user --> action --> __second_user
    if __action == 'accept':
        __link = query_strings.friend_request_accepted.format(
            __second_user, __first_user, __first_user, __second_user)
    elif __action == 'decline':
        __link = query_strings.friend_request_rejected.format(
            __second_user, __first_user)
    else:
        raise HTTP_400_Exception('Invalid action field - ' + __action)

    try:
        with connection.cursor() as cur:
            cur.execute(__link)
            connection.commit()
    except pymysql.err.IntegrityError:
        raise HTTP_204_Exception('User not found')

    body = Body()
    return body
예제 #2
0
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
예제 #3
0
def post(request, query_str_param, connection):
    if query_str_param is None:
        query_str_param = {}

    if 'events' in request:
        events = request['events']  # call from event scraper
    else:
        events = [request]  # call from frontend

    # verify all events first
    for event in events:
        verify_events(event)

    for event in events:

        # set global location variables to current location for convenience
        set_location_variables(event['location'])

        # using the query strings to search for location and adding location if it doesn't exist
        command_get_loc = query_strings.search_for_location.format(
            __street, __city, __zip)

        # using the query string to add location if it wasn't found.
        command_add_loc = query_strings.add_location.format(
            __street, __city, __state, __zip, __country, __latitude,
            __longitude)

        # Check Get_Loc first to see if id is already there so we don't duplicate ids
        location_id = get_loc_id(command_add_loc, command_get_loc, connection)

        # Check if event is not already in the Data Base
        command_search_event = query_strings.search_for_event_in_db.format(
            event['name'], location_id)
        new_event = verify_new_event(command_search_event, connection)

        if new_event is False:
            continue
        # post the edited information of the event onto the data_base
        command_add_event = query_strings.add_event_all_fields_except_host.format(
            event['name'], event['type'], location_id, event['event_date'],
            event['start_time'], event['end_time'], event['is_public'],
            event['is_free'], event['points'], event['image'],
            event['description'], event['url'])
        with connection.cursor() as cur:
            cur.execute(command_add_event)
            connection.commit()

    body = Body()
    return body
예제 #4
0
def post(request, connection):

    try:
        __first_user = request['user_1']
        __second_user = request['user_2']
    except KeyError:
        raise HTTP_400_Exception('Missing required field(s)')

    # __first_user sends request to __second_user
    __link = query_strings.friend_requested.format(__first_user, __second_user,
                                                   'NULL')
    with connection.cursor() as cur:
        try:
            cur.execute(__link)
            connection.commit()
        except pymysql.err.IntegrityError:
            raise HTTP_204_Exception('User not found')

    body = Body()
    return body
예제 #5
0
def get(request, query_str_param, connection):
    body = Body()

    # return all events if query_str_param is None
    if query_str_param is None:
        body.setBody(get_events(connection))
        return body

    if 'city' in query_str_param:
        city = query_str_param['city']
        city = city.lower()
        body.setBody(get_events(connection, city))
        return body

    if 'event_id' in query_str_param:
        event_id = query_str_param['event_id']
        event = get_events(connection, None, event_id)
        if len(event) == 0:
            return body
        else:
            body.setBody(event[0])
            return body

    raise HTTP_400_Exception('Missing required fields for get events')
예제 #6
0
def post(request, query_str_param, connection):
    """
    This method is used to make the POST request in for the /users resource

    :param request: the request_body dict object
    :param connection: the open connection to the MySQL database
    :param query_str_param: the query string parameters dict object
    :return: the response body
    """

    if query_str_param is None:
        query_str_param = {}

    set_variables(request)

    db_add_user = get_add_user_command(connection)

    # add new user to the database
    with connection.cursor() as cur:
        cur.execute(db_add_user)
        connection.commit()

    body = Body()
    return body
예제 #7
0
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
예제 #8
0
def put(request, query_str_param, connection):
    body = Body()
    body.addParameter('message', 'missions.put has been called')
    return body
예제 #9
0
def delete(request, query_str_param, connection):
    body = Body()
    body.addParameter('message', 'events.delete has been called')
    return body
예제 #10
0
def put(request, connection):
    body = Body()
    body.addParameter('message', 'plan.put has been called')
    return body
예제 #11
0
def get(request, connection):
    body = Body()
    body.addParameter('message', 'mai.get has been called')
    return body
예제 #12
0
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