Esempio n. 1
0
def getAllInfo(theList):
    newList = []
    for i in range(len(theList)):
        temp = dynamoPosts.getPost(int(theList[i]))
        if temp is None:
            continue
        votes = r.hget(temp['PostID'], 'total')
        temp['Total_Votes'] = votes
        newList.append(temp)
    return newList
Esempio n. 2
0
def get_votes_by_id(id):
    #SQL CODE
    post = queries.post_by_id(id=id)
    #REDIS
    Post = dynamoPosts.getPost(id)
    if Post:
        #SQL
        post = queries.votes_by_post_id(post=id)
        # return post, status.HTTP_200_OK
        votes = r.hgetall(id)
        return votes, status.HTTP_200_OK
    return {'message': f'post with id {id} not found'}, status.HTTP_404_NOT_FOUND
Esempio n. 3
0
def downvote(id):
    #SQL
    post = queries.post_by_id(id=id)
    #REDIS
    Post = dynamoPosts.getPost(id)
    if Post:
        queries.downvote_post(post=id)
        r.hincrby(id, 'downvotes', 1)
        r.hincrby(id, 'total', -1)
        total = int(r.hget(id, 'total'))
        r.zadd('votes', {id:total})
        r.zadd(Post['subreddit'], {id:total})
        return {'message': f'downvoted post with id {id}'}, status.HTTP_200_OK
    return {"error" : f"Post with id {id} not found"}, status.HTTP_404_NOT_FOUND
Esempio n. 4
0
def post(id):
    if request.method == 'GET':
        return dynamoPosts.getPost(id)
        # return get_post_by_id(id)
    elif request.method == 'DELETE':
        return dynamoPosts.deletePost(id)