Exemple #1
0
def del_post(id_post):
    try:
        post_from_db = Post.get(id = id_post)
        post_from_db.delete_instance()

        return _jsonify(200, 'Postagem excluída com sucesso!')
    except Post.DoesNotExist:
        abort(404)
Exemple #2
0
def edit_post(id_post):
    data_from_client = request.json

    try:
        post_from_db = Post.get(id = id_post)
    except Post.DoesNotExist:
        abort(404)

    post_from_db.title = data_from_client['title']
    post_from_db.content = data_from_client['content']
    post_from_db.emitDate = data_from_client['emitDate']
    post_from_db.expireDate = data_from_client['expireDate']
    post_from_db.save()

    return _jsonify(200, 'Postagem salva com sucesso!')
Exemple #3
0
def post(id_post):
    try:
        post = Post.get(id=id_post)
        return jsonify(post.to_dict())
    except Post.DoesNotExist:
        abort(404)