Сделал нормальные JSON ответы
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b0bd579357
commit
f4732836ad
15
main.py
15
main.py
@ -101,19 +101,22 @@ class Back():
|
|||||||
return str(dict_posts)
|
return str(dict_posts)
|
||||||
|
|
||||||
def updatePost(self, name, body):
|
def updatePost(self, name, body):
|
||||||
# TODO: return RESTful error/success result
|
|
||||||
# If post exists, update it
|
# If post exists, update it
|
||||||
if posts.find_one({'name': name}):
|
if posts.find_one({'name': name}):
|
||||||
newPost = {'$set': {'text': body}}
|
newPostJson = {'$set': {'text': body}}
|
||||||
return str(posts.update_one({'name': name}, newPost))
|
newPost = posts.update_one({'name': name}, newPostJson)
|
||||||
|
result = dict(
|
||||||
|
status=200, state='updated', count=newPost.matched_count
|
||||||
|
)
|
||||||
# Else - create new
|
# Else - create new
|
||||||
else:
|
else:
|
||||||
newPost = {'name': name, 'text': body,
|
newPostJson = {'name': name, 'text': body,
|
||||||
'create_timestamp': str(time.time())}
|
'create_timestamp': str(time.time())}
|
||||||
return str(posts.insert_one(newPost).inserted_id)
|
newPost = posts.insert_one(newPost).inserted_id
|
||||||
|
result = dict(status=200, state='new')
|
||||||
|
return str(result)
|
||||||
|
|
||||||
def deletePost(self, name):
|
def deletePost(self, name):
|
||||||
# TODO: return RESTful error/success result
|
|
||||||
delete = posts.delete_one({'name': name}).deleted_count
|
delete = posts.delete_one({'name': name}).deleted_count
|
||||||
if not delete:
|
if not delete:
|
||||||
result = dict(status=500, count=delete)
|
result = dict(status=500, count=delete)
|
||||||
|
Loading…
Reference in New Issue
Block a user