コード例 #1
0
def update_comment(id):
    body = request.get_json(force=True)

    update = CommentSchema().load(body)
    updated = db.query(Comment).filter(
        Comment.id == id, Comment.author_id == g.user.id).update(update)
    db.commit()

    return jsonify({'success': True if updated else False})
コード例 #2
0
ファイル: posts.py プロジェクト: crisshaker/flask-api-trial
def comment_on_post(id):
    body = request.get_json(force=True)

    data = CommentSchema(only=['body']).load(body)
    comment = Comment(**data, author_id=g.user.id, post_id=id)
    db.add(comment)
    db.commit()

    return jsonify(CommentSchema().dump(comment))
コード例 #3
0
ファイル: posts.py プロジェクト: crisshaker/flask-api-trial
def update_post(id):
    body = request.get_json(force=True)

    update = PostSchema(only=['title', 'body']).load(body)
    updated = db.query(Post).filter(Post.id == id,
                                    Post.author_id == g.user.id).update(update)
    db.commit()

    return jsonify({'success': True if updated else False})
コード例 #4
0
ファイル: posts.py プロジェクト: crisshaker/flask-api-trial
def create_post():
    body = request.get_json(force=True)

    data = PostSchema(only=['post', 'title']).load(body)
    post = Post(**data, author_id=g.user.id)
    db.add(post)
    db.commit()

    return jsonify(PostSchema().dump(post))
コード例 #5
0
ファイル: auth.py プロジェクト: benny-dev/flask-api-trial
def register():
    body = request.get_json(force=True)
    data = UserSchema().load(body)

    username_taken = db.query(User).filter(
        User.username == data['username']).first()
    if username_taken:
        return jsonify({'errors': {'username': '******'}})

    user = User(**data)
    db.add(user)
    db.commit()
    token = jwt.encode({'user_id': user.id}, JWT_SECRET).decode('utf-8')
    return jsonify({'token': token})
コード例 #6
0
def delete_comment(id):
    deleted = db.query(Comment).filter(
        Comment.id == id, Comment.author_id == g.user.id).delete()
    db.commit()

    return jsonify({'success': True if deleted else False})