Добавил получение всех постов
This commit is contained in:
parent
6b4325f835
commit
45b833df6a
27
main.py
27
main.py
@ -12,13 +12,17 @@ posts = database['posts']
|
|||||||
|
|
||||||
@route('/post/<name>')
|
@route('/post/<name>')
|
||||||
def post(name):
|
def post(name):
|
||||||
|
'''
|
||||||
|
Get post
|
||||||
|
'''
|
||||||
return posts.find_one({'name':name})['text']
|
return posts.find_one({'name':name})['text']
|
||||||
|
|
||||||
# /post [POST]
|
|
||||||
|
|
||||||
|
|
||||||
@route('/post/<name>', method='POST')
|
@route('/post/<name>', method='POST')
|
||||||
def post(name):
|
def post(name):
|
||||||
|
'''
|
||||||
|
Insert/Update post
|
||||||
|
'''
|
||||||
body = request.forms.get('body')
|
body = request.forms.get('body')
|
||||||
# If post exists, update it
|
# If post exists, update it
|
||||||
if posts.find_one({'name': name}):
|
if posts.find_one({'name': name}):
|
||||||
@ -30,18 +34,23 @@ def post(name):
|
|||||||
return str(posts.insert_one(newPost).inserted_id)
|
return str(posts.insert_one(newPost).inserted_id)
|
||||||
|
|
||||||
|
|
||||||
# /post [DELETE]
|
|
||||||
|
|
||||||
@route('/post/<name>', method='DELETE')
|
@route('/post/<name>', method='DELETE')
|
||||||
def post(name):
|
def post(name):
|
||||||
|
'''
|
||||||
|
Delete post by name
|
||||||
|
'''
|
||||||
return str(posts.delete_one({'name':name}))
|
return str(posts.delete_one({'name':name}))
|
||||||
|
|
||||||
# /debug (database)
|
@route('/posts')
|
||||||
|
def all_posts():
|
||||||
|
'''
|
||||||
|
Returns all posts
|
||||||
|
'''
|
||||||
|
dict_posts = list()
|
||||||
|
for i in posts.find():
|
||||||
|
dict_posts.append(i)
|
||||||
|
|
||||||
|
return str(dict_posts)
|
||||||
@route('/debug')
|
|
||||||
def debug():
|
|
||||||
return type(posts)
|
|
||||||
|
|
||||||
|
|
||||||
@route('/')
|
@route('/')
|
||||||
|
Loading…
Reference in New Issue
Block a user