# -*- coding:utf-8 -*-
# __author__ = 'dayinfinte'

from flask import request, jsonify, url_for
from ..models import Post
from .. import db
from . import api

@api.route('/posts/')
def get_posts():
    posts = Post.query.all()
    return jsonify({'posts': [post.to_json() for post in posts]})

@api.route('/post/<int:id>')
def get_post(id):
    post = Post.query.get_or_404(id)
    return jsonify(post.to_json())

@api.route('/posts/', methods=['POST'])
def new_post():
    post = Post.from_json(request.json)
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, {'Location': url_for('api.get_post', id=post.id, _external=True) }

@api.route('/posts/<int:id>', methods=['PUT'])
def edit_post(id):
    post = Post.query.get_or_404(id)
    post.content = request.json.get('content', post.content)
    db.session.add(post)
    return jsonify(post.to_json())



ef87ab11987d77d1b3d763f6e5d4b34867589999
<mask token>


@api.route('/posts/', methods=['POST'])
def new_post():
    post = Post.from_json(request.json)
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, {'Location': url_for(
        'api.get_post', id=post.id, _external=True)}


@api.route('/posts/<int:id>', methods=['PUT'])
def edit_post(id):
    post = Post.query.get_or_404(id)
    post.content = request.json.get('content', post.content)
    db.session.add(post)
    return jsonify(post.to_json())

<mask token>


@api.route('/posts/')
def get_posts():
    posts = Post.query.all()
    return jsonify({'posts': [post.to_json() for post in posts]})


<mask token>


@api.route('/posts/', methods=['POST'])
def new_post():
    post = Post.from_json(request.json)
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, {'Location': url_for(
        'api.get_post', id=post.id, _external=True)}


@api.route('/posts/<int:id>', methods=['PUT'])
def edit_post(id):
    post = Post.query.get_or_404(id)
    post.content = request.json.get('content', post.content)
    db.session.add(post)
    return jsonify(post.to_json())

<mask token>


@api.route('/posts/')
def get_posts():
    posts = Post.query.all()
    return jsonify({'posts': [post.to_json() for post in posts]})


@api.route('/post/<int:id>')
def get_post(id):
    post = Post.query.get_or_404(id)
    return jsonify(post.to_json())


@api.route('/posts/', methods=['POST'])
def new_post():
    post = Post.from_json(request.json)
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, {'Location': url_for(
        'api.get_post', id=post.id, _external=True)}


@api.route('/posts/<int:id>', methods=['PUT'])
def edit_post(id):
    post = Post.query.get_or_404(id)
    post.content = request.json.get('content', post.content)
    db.session.add(post)
    return jsonify(post.to_json())

from flask import request, jsonify, url_for
from ..models import Post
from .. import db
from . import api


@api.route('/posts/')
def get_posts():
    posts = Post.query.all()
    return jsonify({'posts': [post.to_json() for post in posts]})


@api.route('/post/<int:id>')
def get_post(id):
    post = Post.query.get_or_404(id)
    return jsonify(post.to_json())


@api.route('/posts/', methods=['POST'])
def new_post():
    post = Post.from_json(request.json)
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, {'Location': url_for(
        'api.get_post', id=post.id, _external=True)}


@api.route('/posts/<int:id>', methods=['PUT'])
def edit_post(id):
    post = Post.query.get_or_404(id)
    post.content = request.json.get('content', post.content)
    db.session.add(post)
    return jsonify(post.to_json())

# -*- coding:utf-8 -*-
# __author__ = 'dayinfinte'

from flask import request, jsonify, url_for
from ..models import Post
from .. import db
from . import api

@api.route('/posts/')
def get_posts():
    posts = Post.query.all()
    return jsonify({'posts': [post.to_json() for post in posts]})

@api.route('/post/<int:id>')
def get_post(id):
    post = Post.query.get_or_404(id)
    return jsonify(post.to_json())

@api.route('/posts/', methods=['POST'])
def new_post():
    post = Post.from_json(request.json)
    db.session.add(post)
    db.session.commit()
    return jsonify(post.to_json()), 201, {'Location': url_for('api.get_post', id=post.id, _external=True) }

@api.route('/posts/<int:id>', methods=['PUT'])
def edit_post(id):
    post = Post.query.get_or_404(id)
    post.content = request.json.get('content', post.content)
    db.session.add(post)
    return jsonify(post.to_json())


