コード例 #1
0
ファイル: app.py プロジェクト: sam-w-thomas/puregains_backend
def post_tags(post_id):
    """
    Update a post tags
    :param post_id:
    :return:
    """

    try:
        try:
            assert post_id == request.view_args['post_id']
            if not auth_post(  # authenticate user
                    app.config['SECRET_KEY'],
                    request,
                    post_id
            ):
                return response_unauthorised()
        except:
            return response_notFound()
        try:
            tags = request.json['post_tags']
            current_tags = post.get_post(post_id)['post_tags']
            new_tags = util.tag_validator(current_tags + "," + tags)
            post.update_post(
                post_id,
                new_tags
            )
        except:
            return response_invalid()

        response_json = json_dict({"post_tags": new_tags}, indent=4, default=str)
        return Response(response_json, status=success_code, mimetype='application/json')

    except Exception as e:
        print(e)
        return response_unknown()
コード例 #2
0
def auth_post(key, request, post_id):
    """
    Authenticate a post, ie user editing post
    :param post_id:
    :return:
    """

    username = post.get_post(post_id)['username']

    print(username)

    return authenticated(key, request, username)
コード例 #3
0
ファイル: app.py プロジェクト: sam-w-thomas/puregains_backend
def get_post_info(post_id):
    """
    Get information post
    Formatted as specific in API documentation
    :param post_id:
    :return:
    """

    try:
        assert post_id == request.view_args['post_id']

        try:
            post_info = post.get_post(post_id)
        except:
            return response_notFound()

        response_json = json_dict(post_info, indent=4, default=str)
        return Response(response_json, status=success_code, mimetype='application/json')

    except Exception as e:
        print(e)
        return response_unknown()
コード例 #4
0
ファイル: app.py プロジェクト: sam-w-thomas/puregains_backend
def update_post_likes(post_id):
    """
    Update the likes associated with a post
    :param post_id:
    :return:
    """

    try:
        try:
            json_request = request.json
            username = json_request["username"]
        except:
            return response_invalid()
        if not auth(  # authenticate user
                app.config['SECRET_KEY'],
                request,
                username
        ):
            return response_unauthorised()

        assert post_id == request.view_args['post_id']

        # Get current likes
        try:
            current_likes = post.get_post(post_id)['likes']
        except:
            return response_notFound()
        new_likes = current_likes + 1
        post.update_post(
            post_id,
            likes=new_likes
        )
        response_json = json_dict({"post_likes": new_likes}, indent=4)
        return Response(response_json, status=success_code, mimetype='application/json')

    except Exception as e:
        print(e)
        return response_unknown()
コード例 #5
0
ファイル: app.py プロジェクト: sam-w-thomas/puregains_backend
def delete_tag(post_id):
    """
    Remove tag from post
    :param post_id:
    :return:
    """

    try:
        try:
            if not auth_post(  # authenticate user
                    app.config['SECRET_KEY'],
                    request,
                    post_id
            ):
                return response_unauthorised()
        except:
            return response_notFound()

        try:
            tag = request.json['post_tag']
            current_tags = post.get_post(post_id)['post_tags']
            new_tags = util.tag_validator(
                current_tags.replace(tag, "")
            )
            post.update_post(
                post_id,
                post_tags=new_tags
            )
        except KeyError:
            return response_invalid()

        response_json = json_dict({"post_tags": new_tags}, indent=4, default=str)
        return Response(response_json, status=success_code, mimetype='application/json')

    except Exception as e:
        print(e)
        return response_unknown()
コード例 #6
0
def get_post():
	from post import get_post
	return jsonify({ "text": get_post() })