Beispiel #1
0
def lambda_handler(event, context):
    try:
        if event['like'] == 1:
            result = add_item_by_attrs("UserLike", 'PostId', event['postid'],
                                       'UserId', event['userid'])
            if result == True:
                result = increase1_table_item("Post", "PostId",
                                              event['postid'])
                response = getResultMultiple(result['Attributes'])
            else:
                response = getResultError("User already liked this post")

        else:
            result = delete_item_by_attrs("UserLike", "PostId",
                                          event['postid'], "UserId",
                                          event['userid'])
            if result == True:
                result = decrease1_table_item("Post", "PostId",
                                              event['postid'])
                response = getResultMultiple(result['Attributes'])
            else:
                response = getResultError("User didn't like this post")

    except Exception, e:
        print(e)
        raise e
Beispiel #2
0
def lambda_handler(event, context):
    data=getFolloweesDataByUserId(event['userid'])
    if data['Count'] > 0:
        posts=getPostsByFollowees(data['Items'], event['limit'])
        posts=updatePostLikesAttr(posts, event['userid'])
        response=getResultMultiple(posts)
    else:
        response=getResultMultiple([])

    return response
Beispiel #3
0
def lambda_handler(event, context):
    try:
        if (len(event['value'])) <= 1:
            response = getResultError(
                "Search value must be more than 3 characters")
            return response

        if (event['key'] == 'Password'):
            response = getResultMultiple([])
            return response

        data = scan_table("User", event['key'], event['value'])
        result = extractInfo(data['Items'])
        response = getResultMultiple(result)
    except Exception, e:
        response = getResultError(str(e))
Beispiel #4
0
def lambda_handler(event, context):
    data = get_items("User_Likes_Rank_Analysis", None, None)
    ranks = data['Items']
    ranks.sort(key=convert, reverse=False)
    if len(ranks) >= event['limit']:
        ranks = ranks[:event['limit']]
    users = getUsersByRanks(ranks)
    response = getResultMultiple(users)
    return response
Beispiel #5
0
def lambda_handler(event, context):
    try:
        if event['follow'] == 1:
            result = add_item_by_attrs("Follow", 'Follower', event['follower'],
                                       'Followee', event['followee'])
            if result == True:
                response = getResultMultiple([])
            else:
                response = getResultError(
                    "User already followed the target user")
        else:
            result = delete_item_by_attrs("Follow", "Follower",
                                          event['follower'], "Followee",
                                          event['followee'])
            if result == True:
                response = getResultMultiple([])
            else:
                response = getResultError("User didn't follow the target user")

    except Exception, e:
        print(e)
        raise e
Beispiel #6
0
def lambda_handler(event, context):
    posts = getPosts(event['limit'])
    posts = updatePostLikesAttr(posts, event['userid'])
    response = getResultMultiple(posts)
    return response
Beispiel #7
0
def lambda_handler(event, context):
    filtering_exp = Attr('Follower').eq(event['userid'])
    projection_exp = 'Followee'
    data = get_items("Follow", filtering_exp, projection_exp)
    response = getResultMultiple(data['Items'])
    return response