3 Commits

Author SHA1 Message Date
2785d3d6b6 Пофиксил баг
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone Build is passing
2021-11-01 06:07:41 +03:00
f4732836ad Сделал нормальные JSON ответы
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 06:05:33 +03:00
b0bd579357 Верну тишину
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 05:56:22 +03:00
2 changed files with 11 additions and 8 deletions

17
main.py
View File

@@ -101,19 +101,22 @@ class Back():
return str(dict_posts)
def updatePost(self, name, body):
# TODO: return RESTful error/success result
# If post exists, update it
if posts.find_one({'name': name}):
newPost = {'$set': {'text': body}}
return str(posts.update_one({'name': name}, newPost))
newPostJson = {'$set': {'text': body}}
newPost = posts.update_one({'name': name}, newPostJson)
result = dict(
status=200, state='updated', count=newPost.matched_count
)
# Else - create new
else:
newPost = {'name': name, 'text': body,
'create_timestamp': str(time.time())}
return str(posts.insert_one(newPost).inserted_id)
newPostJson = {'name': name, 'text': body,
'create_timestamp': str(time.time())}
newPost = posts.insert_one(newPostJson).inserted_id
result = dict(status=200, state='new')
return str(result)
def deletePost(self, name):
# TODO: return RESTful error/success result
delete = posts.delete_one({'name': name}).deleted_count
if not delete:
result = dict(status=500, count=delete)

View File

@@ -1,5 +1,5 @@
#!/bin/bash
curl_cmd='curl -w :%{http_code}'
curl_cmd='curl -s -w :%{http_code}'
#curl_cmd='curl -s -w "%{http_code}\t%{stdout}" -o /dev/null'
url='server:8080'
$curl_cmd -X POST $url/admin/post/test -F 'body=testpage' && echo ": Create success" || echo ': create fail'