|
@@ -1,4 +1,3 @@
|
|
|
-from flask import jsonify
|
|
|
from function import RestFunc
|
|
|
restfunc = RestFunc()
|
|
|
|
|
@@ -9,9 +8,9 @@ class MyQuery:
|
|
|
SELECT * FROM rest_user
|
|
|
WHERE (rest_user.name=%s OR rest_user.email=%s) AND rest_user.password=%s;
|
|
|
''', (request_data['login_email'], request_data['login_email'], request_data['password'],), True)
|
|
|
- return restfunc.gen_token(result['id'], 5), 200
|
|
|
+ return result
|
|
|
except Exception as ex:
|
|
|
- return jsonify({"msg":str(ex)}), 500
|
|
|
+ return {"msg":str(ex)}, 500
|
|
|
|
|
|
def add_query(self, request_data):
|
|
|
try:
|
|
@@ -20,7 +19,7 @@ class MyQuery:
|
|
|
WHERE rest_user.name=%s OR rest_user.email=%s;
|
|
|
''', (request_data['name'], request_data['email']))
|
|
|
if(proverka):
|
|
|
- return jsonify({"msg":"User exist!"}), 400
|
|
|
+ return {"msg":"User exist!"}, 400
|
|
|
else:
|
|
|
result = restfunc.query_insert('''
|
|
|
INSERT INTO rest_user (name, birthday, lastlogintime, insys, idrole, email, password)
|
|
@@ -32,16 +31,16 @@ class MyQuery:
|
|
|
request_data['role_id'], request_data['email'], request_data['password']))
|
|
|
return result, 201
|
|
|
except Exception as ex:
|
|
|
- return jsonify({"msg":str(ex)}), 500
|
|
|
+ return {"msg":str(ex)}, 500
|
|
|
|
|
|
def get_user_query(self, id):
|
|
|
try:
|
|
|
result = restfunc.query_select('''
|
|
|
SELECT * FROM rest_user WHERE id = %s;
|
|
|
''', (id,), True)
|
|
|
- return jsonify(result), 200
|
|
|
+ return result, 200
|
|
|
except Exception as ex:
|
|
|
- return jsonify({"msg":str(ex)}), 500
|
|
|
+ return {"msg":str(ex)}, 500
|
|
|
|
|
|
def get_all_user_query(self):
|
|
|
try:
|
|
@@ -51,34 +50,34 @@ class MyQuery:
|
|
|
WHERE rest_user.idrole = rest_role.id
|
|
|
ORDER BY id ASC;
|
|
|
''', (), False)
|
|
|
- return jsonify(result), 200
|
|
|
+ return result, 200
|
|
|
except Exception as ex:
|
|
|
- return jsonify({"msg":str(ex)}), 500
|
|
|
+ return {"msg":str(ex)}, 500
|
|
|
|
|
|
def delete_user_query(self, request_data):
|
|
|
try:
|
|
|
- result = restfunc.query_delete('''
|
|
|
+ result = restfunc.query_delete_update('''
|
|
|
DELETE FROM rest_user
|
|
|
WHERE id = %s;
|
|
|
''', (request_data['id'],))
|
|
|
if(result):
|
|
|
- return jsonify({"msg":"Successful removal!"}), 200
|
|
|
+ return {"msg":"Successful removal!"}, 200
|
|
|
else:
|
|
|
- return jsonify({"msg":"User does not exist!"}), 400
|
|
|
+ return {"msg":"User does not exist!"}, 400
|
|
|
except Exception as ex:
|
|
|
- return jsonify({"msg":str(ex)}), 500
|
|
|
+ return {"msg":str(ex)}, 500
|
|
|
|
|
|
def update_user_query(self, request_data, id):
|
|
|
try:
|
|
|
- result = restfunc.query_update(f'''
|
|
|
+ result = restfunc.query_delete_update(f'''
|
|
|
UPDATE rest_user
|
|
|
SET name = %s
|
|
|
WHERE id = %s;
|
|
|
''', (request_data['name'], id))
|
|
|
if(result):
|
|
|
- return jsonify({"msg":"Successful update!"}), 200
|
|
|
+ return {"msg":"Successful update!"}, 200
|
|
|
else:
|
|
|
- return jsonify({"msg":"User does not exist!"}), 400
|
|
|
+ return {"msg":"User does not exist!"}, 400
|
|
|
except Exception as ex:
|
|
|
- return jsonify({"msg":str(ex)}), 500
|
|
|
+ return {"msg":str(ex)}, 500
|
|
|
|