finish user API migration to DB

This commit is contained in:
ІО-23 Шмуляр Олег 2024-12-28 12:49:54 +02:00
parent 7ef08e64c2
commit c2104fd9cc
1 changed files with 18 additions and 10 deletions

View File

@ -66,7 +66,9 @@ def ep_healthcheck():
@app.route("/reset_users_because_postman_is_dumb_like_that") @app.route("/reset_users_because_postman_is_dumb_like_that")
def ep_reset(): def ep_reset():
return {} db.session.query(UserModel).delete()
db.session.commit()
return {}, 200
@app.route("/users", methods = ["GET"]) @app.route("/users", methods = ["GET"])
def ep_users_get(): def ep_users_get():
@ -75,12 +77,12 @@ def ep_users_get():
@app.route("/user/<user_id>", methods = ["GET"]) @app.route("/user/<user_id>", methods = ["GET"])
def ep_user_get(user_id): def ep_user_get(user_id):
user = ldb.get_user(user_id) result = db.session.query(UserModel).filter(UserModel.uuid == user_id).all()
if 'uuid' in user: if len(result) == 1:
return user return user_schema.dumps(result[0]), 200
else: else:
return user, 404 return {}, 404
@app.route("/user", methods = ["POST"]) @app.route("/user", methods = ["POST"])
def ep_user_post(): def ep_user_post():
@ -112,12 +114,18 @@ def ep_user_post():
@app.route("/user/<user_id>", methods = ["DELETE"]) @app.route("/user/<user_id>", methods = ["DELETE"])
def ep_user_delete(user_id): def ep_user_delete(user_id):
r = ldb.del_user(user_id) try:
result = db.session.query(UserModel).filter(UserModel.uuid == user_id).all()
except Exception as e:
return {}, 403
if 'uuid' in r: if len(result) == 0:
return r return {}, 404
else:
return r, 403 db.session.query(UserModel).filter(UserModel.uuid == user_id).delete()
db.session.commit()
return user_schema.dumps(result[0]), 200
@app.route("/category", methods = ["GET"]) @app.route("/category", methods = ["GET"])
def ep_category_get(): def ep_category_get():