Compare commits
2 Commits
7ef08e64c2
...
b96ba3eb34
Author | SHA1 | Date |
---|---|---|
|
b96ba3eb34 | |
|
c2104fd9cc |
|
@ -66,7 +66,9 @@ def ep_healthcheck():
|
|||
|
||||
@app.route("/reset_users_because_postman_is_dumb_like_that")
|
||||
def ep_reset():
|
||||
return {}
|
||||
db.session.query(UserModel).delete()
|
||||
db.session.commit()
|
||||
return {}, 200
|
||||
|
||||
@app.route("/users", methods = ["GET"])
|
||||
def ep_users_get():
|
||||
|
@ -75,12 +77,12 @@ def ep_users_get():
|
|||
|
||||
@app.route("/user/<user_id>", methods = ["GET"])
|
||||
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:
|
||||
return user
|
||||
if len(result) == 1:
|
||||
return user_schema.dumps(result[0]), 200
|
||||
else:
|
||||
return user, 404
|
||||
return {}, 404
|
||||
|
||||
@app.route("/user", methods = ["POST"])
|
||||
def ep_user_post():
|
||||
|
@ -112,12 +114,18 @@ def ep_user_post():
|
|||
|
||||
@app.route("/user/<user_id>", methods = ["DELETE"])
|
||||
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:
|
||||
return r
|
||||
else:
|
||||
return r, 403
|
||||
if len(result) == 0:
|
||||
return {}, 404
|
||||
|
||||
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"])
|
||||
def ep_category_get():
|
||||
|
|
|
@ -0,0 +1,58 @@
|
|||
#!/bin/sh
|
||||
|
||||
HOST=$1
|
||||
|
||||
if [ -z HOST ]; then
|
||||
echo "Host not specified, exiting"
|
||||
exit 1;
|
||||
fi;
|
||||
|
||||
echo -n 'Resetting DB...'
|
||||
|
||||
curl -X GET -f -s \
|
||||
http://$HOST:12402/reset_users_because_postman_is_dumb_like_that > /dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'Exiting due to previous error'
|
||||
exit 1
|
||||
fi
|
||||
echo ' Done.'
|
||||
|
||||
echo -n 'Creating users...'
|
||||
for i in $(seq 9); do
|
||||
curl -X POST -f -s \
|
||||
--data "{\"name\": \"hi$i\"}" \
|
||||
--header "Content-Type: application/json" \
|
||||
http://$HOST:12402/user > /dev/null;
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'Exiting due to previous error'
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
echo ' Done.'
|
||||
|
||||
echo -n 'Getting user UUID to delete...'
|
||||
DELETION_UUID=$(curl -X GET -f -s \
|
||||
http://$HOST:12402/users \
|
||||
| jq .[0].uuid);
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'Exiting due to previous error'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DELETION_UUID=${DELETION_UUID#\"}
|
||||
DELETION_UUID=${DELETION_UUID%\"}
|
||||
|
||||
echo " $DELETION_UUID."
|
||||
|
||||
echo -n "Deleting user $DELETION_UUID..."
|
||||
curl -X DELETE -f -s \
|
||||
http://127.0.0.1:12402/user/$DELETION_UUID > /dev/null
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
echo 'Exiting due to previous error'
|
||||
exit 1
|
||||
fi
|
||||
echo ' Done.'
|
Loading…
Reference in New Issue