Добавил получение всех постов
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>')
|
||||
def post(name):
|
||||
'''
|
||||
Get post
|
||||
'''
|
||||
return posts.find_one({'name':name})['text']
|
||||
|
||||
# /post [POST]
|
||||
|
||||
|
||||
@route('/post/<name>', method='POST')
|
||||
def post(name):
|
||||
'''
|
||||
Insert/Update post
|
||||
'''
|
||||
body = request.forms.get('body')
|
||||
# If post exists, update it
|
||||
if posts.find_one({'name': name}):
|
||||
@ -30,18 +34,23 @@ def post(name):
|
||||
return str(posts.insert_one(newPost).inserted_id)
|
||||
|
||||
|
||||
# /post [DELETE]
|
||||
|
||||
@route('/post/<name>', method='DELETE')
|
||||
def post(name):
|
||||
'''
|
||||
Delete post by 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)
|
||||
|
||||
|
||||
@route('/debug')
|
||||
def debug():
|
||||
return type(posts)
|
||||
return str(dict_posts)
|
||||
|
||||
|
||||
@route('/')
|
||||
|
Loading…
Reference in New Issue
Block a user