示例#1
0
def unlike_action_on_post(username, post_id):
    current_user = generate_user_from_auth_token(
        request.headers.get('access-token'))
    post_user = UserMethods.get_user_by_username(username)
    if current_user.id == post_user.id or \
            post_user.status.value == "public" or \
            FollowerMethods.is_following(current_user.id, post_user.id):
        # send all data like comments, likes and post details
        if not PostMethods.get_record_with_id(post_id):
            raise NotFound("Post not found")
        LikeMethods.delete_record(post_id, post_user.id)
        db.commit()
        return jsonify(dict(message="Successfully unliked the post"))
    else:
        return jsonify(
            dict(message="Profile is private! Follow to unlike the post !")
        ), 400
示例#2
0
def unfollow(followee_username):
    follower_user = generate_user_from_auth_token(
        request.headers.get('access-token'))
    followee_user = UserMethods.get_user_by_username(followee_username)
    if followee_user is None:
        raise NotFound('No user with username {username} found'.format(
            username=followee_username))
    # same user id unfollow request
    if follower_user.id == followee_user.id:
        raise BadRequest('Request cannot be proceesed')

    # check if it follows
    if FollowerMethods.is_following(follower_user.id, followee_user.id):
        unfollow_user(follower_user.id, followee_user.id)

    db.commit()
    return jsonify({"message": "Successfully unfollowed"}), 200
示例#3
0
def create_new_post():
    current_user = generate_user_from_auth_token(
        request.headers.get('access-token'))
    request_data = request.form
    image = request.files.getlist('image')[0]
    post_data = dict(caption=request_data.get('caption'),
                     image=image,
                     user_id=current_user.id)
    post = PostMethods.create_record(**post_data)
    # put in redis list
    post_data['image'] = post.image._public_url
    post_data['post_id'] = post.id
    post_data['username'] = current_user.username
    total_user_posts = redis_client.lrange(current_user.username, 0, -1)
    if len(total_user_posts) == int(app.config.get('MAX_REDIS_CACHED_POSTS')):
        redis_client.rpop()

    redis_client.lpush(current_user.username, json.dumps(post_data))

    db.commit()
    return jsonify({"message": "Hurray your post is on its way !!"}), 200
示例#4
0
def follow(followee_username):
    follower_user = generate_user_from_auth_token(
        request.headers.get('access-token'))
    followee_user = UserMethods.get_user_by_username(followee_username)
    if followee_user is None:
        raise NotFound('No user with username {username} found'.format(
            username=followee_username))

    # same user id follow request
    if follower_user.id == followee_user.id:
        raise BadRequest('Request cannot be proceesed')

    # check if not follows
    if not FollowerMethods.is_following(follower_user.id, followee_user.id):
        if followee_user.status.value == "public":
            follow_public_user(follower_user.id, followee_user.id)
            db.commit()
            return jsonify({"message": "Successfully followed"}), 200
        else:
            send_follow_request(follower_user.id, followee_user.id)
            db.commit()
            return jsonify({"message": "Follow request sent"}), 200
示例#5
0
def signup():
    request_data = request.json
    process_signup(request_data)
    db.commit()
    return jsonify({"message": "Success"}), 200
示例#6
0
def decline_follow_request(follower_id):
    followee_user = generate_user_from_auth_token(
        request.headers.get('access-token'))
    decline_follow_requests(follower_id, followee_user.id)
    db.commit()
    return jsonify({"message": "Follow request declined"}), 200