55 lines
1.1 KiB
Python
55 lines
1.1 KiB
Python
from flask import Flask, request
|
|
import time
|
|
from app.local_db import LocalDB
|
|
|
|
app = Flask(__name__)
|
|
ldb = LocalDB()
|
|
|
|
@app.route("/healthcheck")
|
|
def ep_healthcheck():
|
|
return {
|
|
"date": time.strftime('%Y.%m.%d %H:%M:%S'),
|
|
"status": "OK"
|
|
}
|
|
|
|
@app.route("/reset_users_because_postman_is_dumb_like_that")
|
|
def ep_reset():
|
|
ldb.reset()
|
|
return {}
|
|
|
|
@app.route("/users", methods = ["GET"])
|
|
def ep_users_get():
|
|
return ldb.get_users()
|
|
|
|
@app.route("/user/<user_id>", methods = ["GET"])
|
|
def ep_user_get(user_id):
|
|
user = ldb.get_user(user_id)
|
|
|
|
if 'uuid' in user:
|
|
return user
|
|
else:
|
|
return user, 404
|
|
|
|
@app.route("/user", methods = ["POST"])
|
|
def ep_user_post():
|
|
body = request.json
|
|
|
|
if 'name' in body:
|
|
r = ldb.add_user(body['name'])
|
|
|
|
if 'uuid' in r:
|
|
return r
|
|
else:
|
|
return r, 403
|
|
else:
|
|
return {}, 403
|
|
|
|
@app.route("/user/<user_id>", methods = ["DELETE"])
|
|
def ep_user_delete(user_id):
|
|
r = ldb.del_user(user_id)
|
|
|
|
if 'uuid' in r:
|
|
return r
|
|
else:
|
|
return r, 403
|