Get close working as well
This commit is contained in:
62
src/main.py
62
src/main.py
@@ -1,6 +1,7 @@
|
||||
from flask import Flask, g, jsonify, request
|
||||
import sqlite3
|
||||
import game_tables
|
||||
import key_tables
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@@ -65,46 +66,49 @@ def get_table(table_id):
|
||||
@app.route("/api/tables/<table_id>:start")
|
||||
def activate_table(table_id):
|
||||
db = get_db()
|
||||
c = db.execute("select * from game_keys where game_table_id is null")
|
||||
keys = c.fetchall()
|
||||
c.close()
|
||||
cursor = db.cursor()
|
||||
|
||||
if len(keys) == 0:
|
||||
return "No more unused keys", 400
|
||||
keys = key_tables.get_free_keys(cursor)
|
||||
table = game_tables.read_by_id(table_id, cursor)
|
||||
|
||||
key = convertKey(keys[0])
|
||||
|
||||
c = db.execute(
|
||||
"select game_table_id as id, game_table_name, game_table_link, active from game_tables where game_table_id = ?",
|
||||
(table_id,),
|
||||
)
|
||||
tables = c.fetchall()
|
||||
c.close()
|
||||
|
||||
if len(tables) == 0:
|
||||
if table == None:
|
||||
return "No such table", 404
|
||||
|
||||
table = convertTable(tables[0])
|
||||
if table["active"]:
|
||||
if table.active:
|
||||
return "Table already active", 400
|
||||
|
||||
c = db.cursor()
|
||||
c.execute(
|
||||
"UPDATE game_tables SET active = 1 WHERE game_table_id = ?", (table["id"],)
|
||||
)
|
||||
c.execute(
|
||||
"UPDATE game_keys SET game_table_id = ? WHERE key = ?",
|
||||
(table["id"], key["key"]),
|
||||
)
|
||||
c.close()
|
||||
db.commit()
|
||||
if len(keys) == 0:
|
||||
return "No more keys", 400
|
||||
|
||||
return jsonify(table)
|
||||
keys[0].reserve(table.game_table_id)
|
||||
table.active = True
|
||||
keys[0].commit(cursor)
|
||||
table.commit(cursor)
|
||||
cursor.close()
|
||||
db.commit()
|
||||
return jsonify(table.toJson())
|
||||
|
||||
|
||||
@app.route("/api/tables/<table_id>:stop")
|
||||
def deactivate_table(table_id):
|
||||
return
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
|
||||
table = game_tables.read_by_id(table_id, cursor)
|
||||
key = key_tables.get_key_for_table(table_id, cursor)
|
||||
|
||||
if table == None:
|
||||
"No such table", 404
|
||||
|
||||
table.active = False
|
||||
if key != None:
|
||||
key.release()
|
||||
|
||||
table.commit(cursor)
|
||||
key.commit(cursor)
|
||||
cursor.close()
|
||||
db.commit()
|
||||
return jsonify(table.toJson())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user