7 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
fd341bd9df Поправил тест
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 05:54:36 +03:00
4608125fdf Smol fixes 2021-11-01 05:25:57 +03:00
8e52e543f9 Верну проброс конфига
All checks were successful
continuous-integration/drone/push Build is passing
2021-11-01 05:19:39 +03:00
80aeafa013 Короче проще поправить конфиг 2021-11-01 05:17:40 +03:00
4 changed files with 29 additions and 12 deletions

View File

@@ -2,4 +2,7 @@
host = db host = db
port = 27017 port = 27017
name = pycms name = pycms
[App]
host = 0.0.0.0
port = 8080
debug = True

View File

@@ -6,6 +6,8 @@ services:
- 8080:8080 - 8080:8080
depends_on: depends_on:
- db - db
volumes:
- ./config.ini:/app/config.ini
db: db:
image: mongo image: mongo
tests: tests:

31
main.py
View File

@@ -16,6 +16,10 @@ class Config:
- host - host
- port - port
- dbname - dbname
App:
- host
- port
- debug
""" """
def __init__(self): def __init__(self):
""" """
@@ -28,9 +32,8 @@ class Config:
print('DB not found, creating') print('DB not found, creating')
database = mongoclient[self.dbname] database = mongoclient[self.dbname]
# TODO: Create table if not exists
if 'posts' not in database.list_collection_names(): if 'posts' not in database.list_collection_names():
print('Table not fount, creating') print('Table not found, creating')
posts = database['posts'] posts = database['posts']
self.posts = posts self.posts = posts
@@ -98,20 +101,28 @@ 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(newPostJson).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
return bool(posts.delete_one({'name': name}).deleted_count) if not delete:
result = dict(status=500, count=delete)
else:
result = dict(status=200, count=delete)
return str(result)
class Metrics: class Metrics:

View File

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