Ejemplo n.º 1
0
def handler(event, context):
    """
        Update user profile with new data. Makes query for existing data and combines it with new data.
    """
    logging.info(json.dumps(event))
    body = event.get("body")
    if not body:
        return _create_http_response(400,
                                     {"failure_reason": "No body in message!"})
    parsed = _json_string_to_dict(body)

    if not parsed.get("user-id"):
        return _create_http_response(400,
                                     {"failure_reason": "No user ID in body"})

    if parsed.get("failure_reason"):
        return _create_http_response(
            400, {"failure_reason": parsed["failure_reason"]})

    old_data = _get_old_data_items(query_db(parsed["user-id"]))
    if old_data:
        combined_data = _combine_user_data(parsed, old_data)
        write_to_db(combined_data)
        return _create_http_response(200, combined_data)
    else:
        write_to_db(parsed)
        return _create_http_response(200, parsed)
Ejemplo n.º 2
0
def query_data_get_result(query_id, table_name, index_name):
    """
        Query data from dynamo and return the result Items.
    """
    query_response = query_db(query_id, table_name, index_name)
    response = _check_that_result_contains_items(query_response)
    return response
Ejemplo n.º 3
0
def handler(event, context):
    """
        Query dynamo with user-id and return all profile review data.
    """
    logging.info(json.dumps(event))
    request = _parse_request_parameters(event)
    if "failure_reason" in request:
        return _create_http_response(400, request)
    db_items = query_db(request["ride-id"])
    if db_items["Items"]:
        return _create_http_response(200, db_items["Items"][0])
    return _create_http_response(200, {"messages": []})
Ejemplo n.º 4
0
def _db_search_existing_ride(ride_id):
    response = query_db(ride_id)
    chat_history = response.get("Items")
    if chat_history:
        return chat_history[0]
    return {}