Smart curosr for Game Tables
This commit is contained in:
29
src/main.py
29
src/main.py
@@ -1,6 +1,6 @@
|
||||
from flask import Flask, g, jsonify, request
|
||||
import sqlite3
|
||||
import game_tables
|
||||
from game_tables import GameService, GameTable
|
||||
from key_tables import KeyService, KeyTable
|
||||
import container_managment
|
||||
|
||||
@@ -36,31 +36,22 @@ def close_connection(exception):
|
||||
|
||||
@app.route("/api/active_tables")
|
||||
def get_active_tables():
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
tables = game_tables.read_active(cursor)
|
||||
cursor.close()
|
||||
|
||||
gameService = GameService(get_db())
|
||||
tables = gameService.read_active()
|
||||
return jsonify([table.toJson() for table in tables])
|
||||
|
||||
|
||||
@app.route("/api/tables")
|
||||
def get_tables():
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
tables = game_tables.read_all(cursor)
|
||||
cursor.close()
|
||||
|
||||
gameService = GameService(get_db())
|
||||
tables = gameService.read_all()
|
||||
return jsonify([table.toJson() for table in tables])
|
||||
|
||||
|
||||
@app.route("/api/tables/<table_id>")
|
||||
def get_table(table_id):
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
table = game_tables.read_by_id(table_id, cursor)
|
||||
cursor.close()
|
||||
|
||||
gameService = GameService(get_db())
|
||||
table = gameService.read_by_id(table_id)
|
||||
return jsonify(table.toJson())
|
||||
|
||||
|
||||
@@ -69,9 +60,10 @@ def activate_table(table_id):
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
keyService = KeyService(db)
|
||||
gameService = GameService(db)
|
||||
|
||||
keys = keyService.get_free_keys(cursor)
|
||||
table = game_tables.read_by_id(table_id, cursor)
|
||||
table = gameService.read_by_id(table_id, cursor)
|
||||
|
||||
if table == None:
|
||||
return "No such table", 404
|
||||
@@ -98,8 +90,9 @@ def deactivate_table(table_id):
|
||||
db = get_db()
|
||||
cursor = db.cursor()
|
||||
keyService = KeyService(db)
|
||||
gameService = GameService(db)
|
||||
|
||||
table = game_tables.read_by_id(table_id, cursor)
|
||||
table = gameService.read_by_id(table_id, cursor)
|
||||
key = keyService.get_key_for_table(table_id, cursor)
|
||||
|
||||
if table == None:
|
||||
|
||||
Reference in New Issue
Block a user