mirror of
https://github.com/IgorL123/mafia_api.git
synced 2026-09-24 07:30:15 +00:00
refactoring-1
This commit is contained in:
+2
-1
@@ -1,4 +1,5 @@
|
|||||||
venv
|
venv
|
||||||
setiings.json
|
setiings.json
|
||||||
.vscode
|
.vscode
|
||||||
__pycache__
|
__pycache__
|
||||||
|
.idea/
|
||||||
@@ -2,17 +2,17 @@ from flask import Flask, request, jsonify
|
|||||||
import db
|
import db
|
||||||
import api_functions
|
import api_functions
|
||||||
|
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/action', methods=["POST"])
|
@app.route('/action', methods=["POST"])
|
||||||
def action(): # put application's code here
|
def action():
|
||||||
|
# TODO: обработка ошибок + логи
|
||||||
data = request.json
|
data = request.json
|
||||||
trueChatID = data['chatID']
|
true_chat_id = data['chatID']
|
||||||
killedUserID = data['KilledUserID']
|
killed_user_id = data['KilledUserID']
|
||||||
healedUserID = data['HealedUserID']
|
healed_user_id = data['HealedUserID']
|
||||||
checkedUserID = data['CheckedUserID']
|
checked_user_id = data['CheckedUserID']
|
||||||
|
|
||||||
response = {
|
response = {
|
||||||
"killedUserId": None,
|
"killedUserId": None,
|
||||||
@@ -20,46 +20,49 @@ def action(): # put application's code here
|
|||||||
"checkedRole": False
|
"checkedRole": False
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = db.cursor
|
cursor = db.cursor
|
||||||
|
|
||||||
if killedUserID != healedUserID:
|
if killed_user_id != healed_user_id:
|
||||||
cur.execute(f"Select UserID from chats join userschats uc on uc.chatid = chats.chatid join "
|
cursor.execute(f"Select UserID from chats join userschats uc on uc.chatid = chats.chatid join "
|
||||||
f"users on users.userid = uc.userid where truechatid = '{trueChatID}' and TrueUserID = '{killedUserID}'")
|
f"users on users.userid = uc.userid where truechatid = '{true_chat_id}' "
|
||||||
id = cur.fetchall()[0]
|
f"and TrueUserID = '{killed_user_id}'")
|
||||||
cur.execute(f"UPDATE Users SET isAlive = false WHERE UserID = '{id}'")
|
generated_user_id = cursor.fetchall()[0]
|
||||||
response["killedUserId"] = killedUserID
|
cursor.execute(f"UPDATE Users SET isAlive = false WHERE UserID = '{generated_user_id}'")
|
||||||
|
response["killedUserId"] = killed_user_id
|
||||||
|
|
||||||
cur.execute(f"SELECT role FROM users WHERE TrueUserID ='{checkedUserID}';")
|
cursor.execute(f"SELECT role FROM users WHERE TrueUserID ='{checked_user_id}';")
|
||||||
role = cur.fetchall()[0]
|
role = cursor.fetchall()[0]
|
||||||
|
|
||||||
if role == 4:
|
if role == 4:
|
||||||
response["checkedRole"] = True
|
response["checkedRole"] = True
|
||||||
|
|
||||||
response["isEndGame"] = api_functions.isEnd(cur, trueChatID)
|
response["isEndGame"] = api_functions.isEnd(cursor, true_chat_id)
|
||||||
|
db.close(cursor)
|
||||||
|
|
||||||
return jsonify(response), 200
|
return jsonify(response), 200
|
||||||
|
|
||||||
|
|
||||||
@app.route('/create_chat', methods=["POST"])
|
@app.route('/create_chat', methods=["POST"])
|
||||||
def create():
|
def create():
|
||||||
|
# TODO: обработка ошибок + логи
|
||||||
tci = request.json['chatID']
|
tci = request.json['chatID']
|
||||||
cursor = db.connection.cursor()
|
cursor = db.connection.cursor()
|
||||||
db.query_ins_chat(tci, cursor)
|
db.query_ins_chat(tci, cursor)
|
||||||
|
db.close(cursor)
|
||||||
return 'ok', 200
|
return 'ok', 200
|
||||||
|
|
||||||
|
|
||||||
@app.route('/start_game', methods=["POST"])
|
@app.route('/start_game', methods=["POST"])
|
||||||
def start(): # Команда принимает на вход
|
def start(): # Команда принимает на вход
|
||||||
TCI = request.json['chatID']
|
tci = request.json['chatID']
|
||||||
userlist = request.json['userIDs']
|
user_list = request.json['userIDs']
|
||||||
cursor = db.connection.cursor()
|
cursor = db.connection.cursor()
|
||||||
for idi in userlist:
|
for current_user in user_list:
|
||||||
db.query_ins_user(id, cursor)
|
db.query_ins_user(current_user, cursor)
|
||||||
db.close(cursor)
|
db.close(cursor)
|
||||||
resp = api_functions.role_distribution(userlist)
|
resp = api_functions.role_distribution(user_list)
|
||||||
return "", resp
|
return "", resp
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(host="0.0.0.0", debug=True)
|
app.run(host="0.0.0.0", debug=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user