Merge pull request #12 from sorrelbri/sj-gameroom-endpoints
sj gameroom endpoints
This commit is contained in:
commit
3229ab0f96
21 changed files with 212 additions and 335 deletions
|
@ -1,6 +1,7 @@
|
||||||
from flask import Blueprint, request, jsonify, session
|
from flask import Blueprint, request, jsonify, session
|
||||||
from .users.api_users import api_users
|
from .users.api_users import api_users
|
||||||
from .rooms.api_rooms import api_rooms
|
from .rooms.api_rooms import api_rooms
|
||||||
|
from .games.api_games import api_games
|
||||||
|
|
||||||
from auth.auth import auth
|
from auth.auth import auth
|
||||||
|
|
||||||
|
@ -9,6 +10,7 @@ api = Blueprint('api', __name__, url_prefix='/api')
|
||||||
def register_api_endpoints(app):
|
def register_api_endpoints(app):
|
||||||
app.register_blueprint(api_users)
|
app.register_blueprint(api_users)
|
||||||
app.register_blueprint(api_rooms)
|
app.register_blueprint(api_rooms)
|
||||||
|
app.register_blueprint(api_games)
|
||||||
app.register_blueprint(api)
|
app.register_blueprint(api)
|
||||||
app.register_blueprint(auth)
|
app.register_blueprint(auth)
|
||||||
return app
|
return app
|
||||||
|
|
|
@ -5,11 +5,9 @@ import jwt
|
||||||
def jwt_required():
|
def jwt_required():
|
||||||
def decorator(func):
|
def decorator(func):
|
||||||
def authorized(*args, **kwargs):
|
def authorized(*args, **kwargs):
|
||||||
print(request.headers)
|
|
||||||
auth_header = request.headers.get('Authorization') or None
|
auth_header = request.headers.get('Authorization') or None
|
||||||
if auth_header:
|
if auth_header:
|
||||||
auth_token = auth_header.split(" ")[1]
|
auth_token = auth_header.split(" ")[1]
|
||||||
print(auth_token)
|
|
||||||
if jwt.decode(auth_token, os.environ.get('SECRET_KEY')):
|
if jwt.decode(auth_token, os.environ.get('SECRET_KEY')):
|
||||||
return func(*args, **kwargs)
|
return func(*args, **kwargs)
|
||||||
else:
|
else:
|
||||||
|
|
53
api/games/api_games.py
Normal file
53
api/games/api_games.py
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
from flask import Blueprint, request, jsonify, session
|
||||||
|
from models.User import User, user_schema, users_schema
|
||||||
|
from models.GameRoom import GameRoom, rooms_schema, room_schema
|
||||||
|
from models.Game import Game
|
||||||
|
from database import db
|
||||||
|
from ..decorators import jwt_required
|
||||||
|
import jwt
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
|
||||||
|
api_games = Blueprint('api_games', __name__, url_prefix='/api/games')
|
||||||
|
|
||||||
|
@api_games.route('/', methods=['POST'])
|
||||||
|
@jwt_required()
|
||||||
|
def post_game():
|
||||||
|
print('Hey it\'s a post request!')
|
||||||
|
data = request.get_json()
|
||||||
|
# TODO create decorator that returns user from header
|
||||||
|
auth_header = request.headers.get('Authorization')
|
||||||
|
user = jwt.decode(auth_header.split(" ")[1], os.environ.get('SECRET_KEY'))['user']
|
||||||
|
print(user)
|
||||||
|
print('data')
|
||||||
|
print(data)
|
||||||
|
user_id = json.loads(user)['id']
|
||||||
|
try:
|
||||||
|
game = Game(
|
||||||
|
name = data['name'],
|
||||||
|
description = data['description'],
|
||||||
|
board_size = data['boardSize'],
|
||||||
|
game_room = data['gameRoom'],
|
||||||
|
player_white = user_id
|
||||||
|
)
|
||||||
|
print(game)
|
||||||
|
db.session.add(game)
|
||||||
|
print('game added')
|
||||||
|
db.session.commit()
|
||||||
|
print('game')
|
||||||
|
print(game)
|
||||||
|
response = {
|
||||||
|
'status': 'success',
|
||||||
|
'message': 'Game created',
|
||||||
|
'game': game.id
|
||||||
|
}
|
||||||
|
return jsonify(response), 201
|
||||||
|
except Exception as e:
|
||||||
|
print('error')
|
||||||
|
print(e)
|
||||||
|
print(e.__dict__)
|
||||||
|
response = {
|
||||||
|
'status': 'fail',
|
||||||
|
'message': 'There was an error. Please try again.'
|
||||||
|
}
|
||||||
|
return jsonify(response), 401
|
|
@ -1,7 +0,0 @@
|
||||||
from flask import Blueprint
|
|
||||||
|
|
||||||
game = Blueprint('games', __name__)
|
|
||||||
|
|
||||||
@game.route('/<int:game_id>')
|
|
||||||
def func():
|
|
||||||
pass
|
|
|
@ -1,18 +1,23 @@
|
||||||
from flask import Blueprint, request, jsonify, session
|
from flask import Blueprint, request, jsonify, session
|
||||||
from models.User import User, user_schema, users_schema
|
from models.User import User, user_schema, users_schema
|
||||||
from models.GameRoom import GameRoom
|
from models.GameRoom import GameRoom, rooms_schema, room_schema
|
||||||
|
from models.Game import Game, games_schema
|
||||||
from database import db
|
from database import db
|
||||||
from ..decorators import jwt_required
|
from ..decorators import jwt_required
|
||||||
|
|
||||||
api_rooms = Blueprint('api_rooms', __name__, url_prefix='/api/rooms')
|
api_rooms = Blueprint('api_rooms', __name__, url_prefix='/api/rooms')
|
||||||
|
|
||||||
@api_rooms.route('/<room_id>', methods=['GET'])
|
@api_rooms.route('/<room_id>', methods=['GET'])
|
||||||
def get_room():
|
def get_room(room_id):
|
||||||
pass
|
print(room_id)
|
||||||
|
games = Game.query.filter_by(game_room=room_id).all()
|
||||||
|
response = games_schema.dumps(games)
|
||||||
|
return jsonify(response)
|
||||||
|
|
||||||
@api_rooms.route('/', methods=['GET'])
|
@api_rooms.route('/', methods=['GET'])
|
||||||
def get_rooms():
|
def get_rooms():
|
||||||
response = {"status" : "success"}
|
rooms = GameRoom.query.all()
|
||||||
|
response = rooms_schema.dumps(rooms)
|
||||||
return jsonify(response)
|
return jsonify(response)
|
||||||
|
|
||||||
# protected route
|
# protected route
|
||||||
|
@ -24,11 +29,11 @@ def post_room():
|
||||||
print(data)
|
print(data)
|
||||||
try:
|
try:
|
||||||
room = GameRoom(
|
room = GameRoom(
|
||||||
name = data['name'],
|
name = data['name'],
|
||||||
description = data['description'],
|
description = data['description'],
|
||||||
# TODO add support for private rooms and multiple languages
|
# TODO add support for private rooms and multiple languages
|
||||||
# private = data['private'],
|
# private = data['private'],
|
||||||
# language = data['language']
|
# language = data['language']
|
||||||
)
|
)
|
||||||
db.session.add(room)
|
db.session.add(room)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
@ -39,6 +44,7 @@ def post_room():
|
||||||
}
|
}
|
||||||
return jsonify(response), 201
|
return jsonify(response), 201
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
print(e.__dict__)
|
print(e.__dict__)
|
||||||
response = {
|
response = {
|
||||||
'status': 'fail',
|
'status': 'fail',
|
||||||
|
|
|
@ -9,7 +9,7 @@ def api_get_users():
|
||||||
print('called one')
|
print('called one')
|
||||||
users = User.query.all()
|
users = User.query.all()
|
||||||
response = users_schema.dumps(users)
|
response = users_schema.dumps(users)
|
||||||
return jsonify(response)
|
return jsonify(response), 200
|
||||||
|
|
||||||
|
|
||||||
@api_users.route('/users/account', methods=['GET'])
|
@api_users.route('/users/account', methods=['GET'])
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: 02be4c8fbd69
|
|
||||||
Revises: 0e0f8ad1362d
|
|
||||||
Create Date: 2019-10-09 10:05:32.403967
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '02be4c8fbd69'
|
|
||||||
down_revision = '0e0f8ad1362d'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_table('game_rooms_users',
|
|
||||||
sa.Column('user_id', sa.Integer(), nullable=False),
|
|
||||||
sa.Column('game_rooms_id', sa.Integer(), nullable=False),
|
|
||||||
sa.ForeignKeyConstraint(['game_rooms_id'], ['game_rooms.id'], ),
|
|
||||||
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
|
||||||
sa.PrimaryKeyConstraint('user_id', 'game_rooms_id')
|
|
||||||
)
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_table('game_rooms_users')
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,30 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: 0e0f8ad1362d
|
|
||||||
Revises: 50aab465cf44
|
|
||||||
Create Date: 2019-10-05 23:21:57.620808
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '0e0f8ad1362d'
|
|
||||||
down_revision = '50aab465cf44'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('users', sa.Column('username', sa.String(length=255), nullable=False))
|
|
||||||
op.create_unique_constraint(None, 'users', ['username'])
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_constraint(None, 'users', type_='unique')
|
|
||||||
op.drop_column('users', 'username')
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,28 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: 16c70b11242e
|
|
||||||
Revises: 9519d28f13f0
|
|
||||||
Create Date: 2019-10-02 14:50:27.180692
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '16c70b11242e'
|
|
||||||
down_revision = '9519d28f13f0'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('moves', sa.Column('is_main', sa.Boolean(), nullable=False))
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column('moves', 'is_main')
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,28 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: 50aab465cf44
|
|
||||||
Revises: bfa4b406e22f
|
|
||||||
Create Date: 2019-10-05 22:37:07.643522
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = '50aab465cf44'
|
|
||||||
down_revision = 'bfa4b406e22f'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('users', sa.Column('password', sa.String(length=255), nullable=False))
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column('users', 'password')
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,8 +1,8 @@
|
||||||
"""empty message
|
"""empty message
|
||||||
|
|
||||||
Revision ID: 9519d28f13f0
|
Revision ID: acabfc6d158d
|
||||||
Revises:
|
Revises:
|
||||||
Create Date: 2019-10-02 13:54:17.877590
|
Create Date: 2019-10-10 14:25:27.198731
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from alembic import op
|
from alembic import op
|
||||||
|
@ -10,7 +10,7 @@ import sqlalchemy as sa
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
# revision identifiers, used by Alembic.
|
||||||
revision = '9519d28f13f0'
|
revision = 'acabfc6d158d'
|
||||||
down_revision = None
|
down_revision = None
|
||||||
branch_labels = None
|
branch_labels = None
|
||||||
depends_on = None
|
depends_on = None
|
||||||
|
@ -18,12 +18,10 @@ depends_on = None
|
||||||
|
|
||||||
def upgrade():
|
def upgrade():
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
# ### commands auto generated by Alembic - please adjust! ###
|
||||||
op.create_table('game_rooms',
|
op.create_table('room_languages',
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
sa.Column('name', sa.String(length=40), nullable=False),
|
sa.Column('name', sa.String(length=40), nullable=False),
|
||||||
sa.Column('description', sa.String(length=200), nullable=False),
|
sa.Column('iso', sa.String(length=2), nullable=False),
|
||||||
sa.Column('private', sa.Boolean(), nullable=False),
|
|
||||||
sa.Column('language', sa.Enum(name='languages'), nullable=False),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
sa.PrimaryKeyConstraint('id')
|
||||||
)
|
)
|
||||||
op.create_table('time_settings',
|
op.create_table('time_settings',
|
||||||
|
@ -38,15 +36,33 @@ def upgrade():
|
||||||
)
|
)
|
||||||
op.create_table('users',
|
op.create_table('users',
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('username', sa.String(length=255), autoincrement=True, nullable=False),
|
||||||
sa.Column('email', sa.String(length=255), nullable=False),
|
sa.Column('email', sa.String(length=255), nullable=False),
|
||||||
sa.Column('password', sa.String(length=255), nullable=False),
|
sa.Column('password', sa.String(length=255), nullable=False),
|
||||||
sa.Column('registered_on', sa.DateTime(), nullable=False),
|
sa.Column('registered_on', sa.DateTime(), nullable=False),
|
||||||
sa.Column('admin', sa.Boolean(), nullable=False),
|
sa.Column('admin', sa.Boolean(), nullable=False),
|
||||||
sa.Column('rank', sa.Enum('D7', 'D6', 'D5', 'D4', 'D3', 'D2', 'D1', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'K10', 'K11', 'K12', 'K13', 'K14', 'K15', 'K16', 'K17', 'K18', 'K19', 'K20', 'K21', 'K22', 'K23', 'K24', 'K25', 'K26', 'K27', 'K28', 'K29', 'K30', name='ranks'), nullable=True),
|
sa.Column('rank', sa.Enum('D7', 'D6', 'D5', 'D4', 'D3', 'D2', 'D1', 'K1', 'K2', 'K3', 'K4', 'K5', 'K6', 'K7', 'K8', 'K9', 'K10', 'K11', 'K12', 'K13', 'K14', 'K15', 'K16', 'K17', 'K18', 'K19', 'K20', 'K21', 'K22', 'K23', 'K24', 'K25', 'K26', 'K27', 'K28', 'K29', 'K30', 'UR', name='ranks'), nullable=True),
|
||||||
sa.Column('elo', sa.Integer(), nullable=True),
|
sa.Column('elo', sa.Integer(), nullable=True),
|
||||||
sa.Column('rank_certainty', sa.Boolean(), nullable=False),
|
sa.Column('rank_certainty', sa.Boolean(), nullable=False),
|
||||||
sa.PrimaryKeyConstraint('id'),
|
sa.PrimaryKeyConstraint('id'),
|
||||||
sa.UniqueConstraint('email')
|
sa.UniqueConstraint('email'),
|
||||||
|
sa.UniqueConstraint('username')
|
||||||
|
)
|
||||||
|
op.create_table('game_rooms',
|
||||||
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
sa.Column('name', sa.String(length=40), nullable=False),
|
||||||
|
sa.Column('description', sa.String(length=200), nullable=False),
|
||||||
|
sa.Column('private', sa.Boolean(), nullable=False),
|
||||||
|
sa.Column('language', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['language'], ['room_languages.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('id')
|
||||||
|
)
|
||||||
|
op.create_table('game_rooms_users',
|
||||||
|
sa.Column('user_id', sa.Integer(), nullable=False),
|
||||||
|
sa.Column('game_rooms_id', sa.Integer(), nullable=False),
|
||||||
|
sa.ForeignKeyConstraint(['game_rooms_id'], ['game_rooms.id'], ),
|
||||||
|
sa.ForeignKeyConstraint(['user_id'], ['users.id'], ),
|
||||||
|
sa.PrimaryKeyConstraint('user_id', 'game_rooms_id')
|
||||||
)
|
)
|
||||||
op.create_table('games',
|
op.create_table('games',
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
||||||
|
@ -81,6 +97,8 @@ def upgrade():
|
||||||
sa.Column('x_point', sa.Integer(), nullable=True),
|
sa.Column('x_point', sa.Integer(), nullable=True),
|
||||||
sa.Column('y_point', sa.Integer(), nullable=True),
|
sa.Column('y_point', sa.Integer(), nullable=True),
|
||||||
sa.Column('move_number', sa.Integer(), nullable=True),
|
sa.Column('move_number', sa.Integer(), nullable=True),
|
||||||
|
sa.Column('is_pass', sa.Boolean(), nullable=False),
|
||||||
|
sa.Column('is_main', sa.Boolean(), nullable=False),
|
||||||
sa.Column('game', sa.Integer(), nullable=False),
|
sa.Column('game', sa.Integer(), nullable=False),
|
||||||
sa.Column('preceding_move', sa.Integer(), nullable=True),
|
sa.Column('preceding_move', sa.Integer(), nullable=True),
|
||||||
sa.ForeignKeyConstraint(['game'], ['games.id'], ),
|
sa.ForeignKeyConstraint(['game'], ['games.id'], ),
|
||||||
|
@ -103,7 +121,9 @@ def downgrade():
|
||||||
op.drop_table('messages')
|
op.drop_table('messages')
|
||||||
op.drop_table('moves')
|
op.drop_table('moves')
|
||||||
op.drop_table('games')
|
op.drop_table('games')
|
||||||
|
op.drop_table('game_rooms_users')
|
||||||
|
op.drop_table('game_rooms')
|
||||||
op.drop_table('users')
|
op.drop_table('users')
|
||||||
op.drop_table('time_settings')
|
op.drop_table('time_settings')
|
||||||
op.drop_table('game_rooms')
|
op.drop_table('room_languages')
|
||||||
# ### end Alembic commands ###
|
# ### end Alembic commands ###
|
|
@ -1,30 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: bafcadd8390e
|
|
||||||
Revises: e5b4175be075
|
|
||||||
Create Date: 2019-10-09 15:34:31.194998
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'bafcadd8390e'
|
|
||||||
down_revision = 'e5b4175be075'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('game_rooms', sa.Column('language', sa.Integer(), nullable=False))
|
|
||||||
op.create_foreign_key(None, 'game_rooms', 'room_languages', ['language'], ['id'])
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_constraint(None, 'game_rooms', type_='foreignkey')
|
|
||||||
op.drop_column('game_rooms', 'language')
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,28 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: bdc3cd5d7499
|
|
||||||
Revises: 16c70b11242e
|
|
||||||
Create Date: 2019-10-05 22:34:04.358841
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'bdc3cd5d7499'
|
|
||||||
down_revision = '16c70b11242e'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('moves', sa.Column('is_pass', sa.Boolean(), nullable=False))
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column('moves', 'is_pass')
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,28 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: bfa4b406e22f
|
|
||||||
Revises: bdc3cd5d7499
|
|
||||||
Create Date: 2019-10-05 22:36:45.420054
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from sqlalchemy.dialects import postgresql
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'bfa4b406e22f'
|
|
||||||
down_revision = 'bdc3cd5d7499'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.drop_column('users', 'password')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('users', sa.Column('password', postgresql.TIMESTAMP(), autoincrement=False, nullable=False))
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,35 +0,0 @@
|
||||||
"""empty message
|
|
||||||
|
|
||||||
Revision ID: e5b4175be075
|
|
||||||
Revises: 02be4c8fbd69
|
|
||||||
Create Date: 2019-10-09 15:34:06.312258
|
|
||||||
|
|
||||||
"""
|
|
||||||
from alembic import op
|
|
||||||
import sqlalchemy as sa
|
|
||||||
from sqlalchemy.dialects import postgresql
|
|
||||||
|
|
||||||
# revision identifiers, used by Alembic.
|
|
||||||
revision = 'e5b4175be075'
|
|
||||||
down_revision = '02be4c8fbd69'
|
|
||||||
branch_labels = None
|
|
||||||
depends_on = None
|
|
||||||
|
|
||||||
|
|
||||||
def upgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.create_table('room_languages',
|
|
||||||
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
|
|
||||||
sa.Column('name', sa.String(length=40), nullable=False),
|
|
||||||
sa.Column('iso', sa.String(length=2), nullable=False),
|
|
||||||
sa.PrimaryKeyConstraint('id')
|
|
||||||
)
|
|
||||||
op.drop_column('game_rooms', 'language')
|
|
||||||
# ### end Alembic commands ###
|
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
|
||||||
# ### commands auto generated by Alembic - please adjust! ###
|
|
||||||
op.add_column('game_rooms', sa.Column('language', postgresql.ENUM(name='languages'), autoincrement=False, nullable=False))
|
|
||||||
op.drop_table('room_languages')
|
|
||||||
# ### end Alembic commands ###
|
|
|
@ -1,22 +1,25 @@
|
||||||
from app import db, ma
|
from app import db, ma
|
||||||
|
from marshmallow import fields
|
||||||
import enum
|
import enum
|
||||||
|
from models.User import user_schema
|
||||||
|
|
||||||
class Players(enum.Enum):
|
|
||||||
BLACK = "The player taking black stones"
|
|
||||||
WHITE = "The player taking white stones"
|
|
||||||
VOID = "The game was a draw or voided"
|
|
||||||
|
|
||||||
class WinType(enum.Enum):
|
|
||||||
DRAW = "The game is a draw"
|
|
||||||
RESIGN = "The game ended in resignation"
|
|
||||||
SCORE = "The game ended by counting points"
|
|
||||||
TIME = "The game ended in loss by time out"
|
|
||||||
VOID = "The game was suspended"
|
|
||||||
|
|
||||||
class Game(db.Model):
|
class Game(db.Model):
|
||||||
__tablename__ = "games"
|
__tablename__ = "games"
|
||||||
__table_args__ = {'extend_existing': True}
|
__table_args__ = {'extend_existing': True}
|
||||||
|
|
||||||
|
class Players(enum.Enum):
|
||||||
|
BLACK = "The player taking black stones"
|
||||||
|
WHITE = "The player taking white stones"
|
||||||
|
VOID = "The game was a draw or voided"
|
||||||
|
|
||||||
|
class WinType(enum.Enum):
|
||||||
|
DRAW = "The game is a draw"
|
||||||
|
RESIGN = "The game ended in resignation"
|
||||||
|
SCORE = "The game ended by counting points"
|
||||||
|
TIME = "The game ended in loss by time out"
|
||||||
|
VOID = "The game was suspended"
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
date = db.Column(db.DateTime())
|
date = db.Column(db.DateTime())
|
||||||
komi = db.Column(db.Numeric(2,1), nullable=False)
|
komi = db.Column(db.Numeric(2,1), nullable=False)
|
||||||
|
@ -40,5 +43,23 @@ class Game(db.Model):
|
||||||
player_black = db.Column(db.Integer, db.ForeignKey("users.id"))
|
player_black = db.Column(db.Integer, db.ForeignKey("users.id"))
|
||||||
player_white = db.Column(db.Integer, db.ForeignKey("users.id"))
|
player_white = db.Column(db.Integer, db.ForeignKey("users.id"))
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name, description, board_size, game_room, player_white, komi=0.5, handicap=0, time_settings=1):
|
||||||
pass
|
self.name = name
|
||||||
|
self.description = description
|
||||||
|
self.board_size = board_size
|
||||||
|
self.game_room = game_room
|
||||||
|
self.player_white = player_white
|
||||||
|
self.komi = komi
|
||||||
|
self.handicap = handicap
|
||||||
|
self.time_settings = time_settings
|
||||||
|
print('did it')
|
||||||
|
|
||||||
|
class GameSchema(ma.ModelSchema):
|
||||||
|
id = fields.Int()
|
||||||
|
name = fields.Str()
|
||||||
|
description = fields.Str()
|
||||||
|
boardSize = fields.Int()
|
||||||
|
player = fields.Nested(user_schema)
|
||||||
|
|
||||||
|
game_schema = GameSchema()
|
||||||
|
games_schema = GameSchema(many=True)
|
|
@ -1,4 +1,5 @@
|
||||||
from app import db, ma
|
from app import db, ma
|
||||||
|
from marshmallow import fields
|
||||||
# TODO User >---< GameRoom
|
# TODO User >---< GameRoom
|
||||||
|
|
||||||
# ! Game Room >-< Users join table
|
# ! Game Room >-< Users join table
|
||||||
|
@ -40,3 +41,21 @@ class GameRoom(db.Model):
|
||||||
self.description = description
|
self.description = description
|
||||||
self.private = private
|
self.private = private
|
||||||
self.language = language
|
self.language = language
|
||||||
|
|
||||||
|
class LanguageSchema(ma.ModelSchema):
|
||||||
|
id = fields.Int()
|
||||||
|
name = fields.Str()
|
||||||
|
iso = fields.Str()
|
||||||
|
|
||||||
|
language_schema = LanguageSchema()
|
||||||
|
|
||||||
|
class RoomSchema(ma.ModelSchema):
|
||||||
|
id = fields.Int()
|
||||||
|
name = fields.Str()
|
||||||
|
description = fields.Str()
|
||||||
|
private = fields.Bool()
|
||||||
|
language = fields.Nested(LanguageSchema)
|
||||||
|
|
||||||
|
|
||||||
|
room_schema = RoomSchema()
|
||||||
|
rooms_schema = RoomSchema(many=True)
|
|
@ -1,14 +1,15 @@
|
||||||
from app import db, ma
|
from app import db, ma
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
class Players(enum.Enum):
|
|
||||||
BLACK = "The player taking black stones"
|
|
||||||
WHITE = "The player taking white stones"
|
|
||||||
|
|
||||||
class Message(db.Model):
|
class Message(db.Model):
|
||||||
__tablename__ = "messages"
|
__tablename__ = "messages"
|
||||||
__table_args__ = {'extend_existing': True}
|
__table_args__ = {'extend_existing': True}
|
||||||
|
|
||||||
|
class Players(enum.Enum):
|
||||||
|
BLACK = "The player taking black stones"
|
||||||
|
WHITE = "The player taking white stones"
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
date = db.Column(db.DateTime(), nullable=False)
|
date = db.Column(db.DateTime(), nullable=False)
|
||||||
content = db.Column(db.String(200), nullable=False)
|
content = db.Column(db.String(200), nullable=False)
|
||||||
|
|
|
@ -1,14 +1,15 @@
|
||||||
from app import db, ma
|
from app import db, ma
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
class Players(enum.Enum):
|
|
||||||
BLACK = "The player taking black stones"
|
|
||||||
WHITE = "The player taking white stones"
|
|
||||||
|
|
||||||
class Move(db.Model):
|
class Move(db.Model):
|
||||||
__tablename__ = "moves"
|
__tablename__ = "moves"
|
||||||
__table_args__ = {'extend_existing': True}
|
__table_args__ = {'extend_existing': True}
|
||||||
|
|
||||||
|
class Players(enum.Enum):
|
||||||
|
BLACK = "The player taking black stones"
|
||||||
|
WHITE = "The player taking white stones"
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
player = db.Column(db.Enum(Players))
|
player = db.Column(db.Enum(Players))
|
||||||
x_point = db.Column(db.Integer)
|
x_point = db.Column(db.Integer)
|
||||||
|
|
|
@ -1,15 +1,17 @@
|
||||||
from app import db, ma
|
from app import db, ma
|
||||||
import enum
|
import enum
|
||||||
|
|
||||||
class TimeTypes(enum.Enum):
|
|
||||||
BYOYOMI = "Counting by time period"
|
|
||||||
ABSOLUTE = "One period to use time"
|
|
||||||
HOURGLASS = "Absolute time for both players"
|
|
||||||
NONE = "Untimed"
|
|
||||||
|
|
||||||
class TimeSettings(db.Model):
|
class TimeSettings(db.Model):
|
||||||
|
__tablename__ = "time_settings"
|
||||||
__table_args__ = {'extend_existing': True}
|
__table_args__ = {'extend_existing': True}
|
||||||
|
|
||||||
|
class TimeTypes(enum.Enum):
|
||||||
|
BYOYOMI = "Counting by time period"
|
||||||
|
ABSOLUTE = "One period to use time"
|
||||||
|
HOURGLASS = "Absolute time for both players"
|
||||||
|
NONE = "Untimed"
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
main_time = db.Column(db.Enum(TimeTypes), nullable=False)
|
main_time = db.Column(db.Enum(TimeTypes), nullable=False)
|
||||||
time_period = db.Column(db.Integer) # number of periods
|
time_period = db.Column(db.Integer) # number of periods
|
||||||
|
@ -19,5 +21,6 @@ class TimeSettings(db.Model):
|
||||||
overtime_length = db.Column(db.Integer) # seconds
|
overtime_length = db.Column(db.Integer) # seconds
|
||||||
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, main_time=TimeTypes.NONE, overtime=TimeTypes.NONE):
|
||||||
pass
|
self.main_time = main_time
|
||||||
|
self.overtime = overtime
|
|
@ -8,49 +8,50 @@ import json
|
||||||
import jwt
|
import jwt
|
||||||
import os
|
import os
|
||||||
|
|
||||||
class Ranks(enum.Enum): # with minimal Elo rating
|
|
||||||
D7 = "Seven Dan" # Elo 2700+
|
|
||||||
D6 = "Six Dan"
|
|
||||||
D5 = "Five Dan" # Elo 2500
|
|
||||||
D4 = "Four Dan"
|
|
||||||
D3 = "Three Dan"
|
|
||||||
D2 = "Two Dan"
|
|
||||||
D1 = "One Dan"
|
|
||||||
K1 = "One Kyu" # Elo 2000
|
|
||||||
K2 = "Two Kyu"
|
|
||||||
K3 = "Three Kyu"
|
|
||||||
K4 = "Four Kyu"
|
|
||||||
K5 = "Five Kyu"
|
|
||||||
K6 = "Six Kyu" # Elo 1500
|
|
||||||
K7 = "Seven Kyu"
|
|
||||||
K8 = "Eight Kyu"
|
|
||||||
K9 = "Nine Kyu"
|
|
||||||
K10 = "Ten Kyu"
|
|
||||||
K11 = "Eleven Kyu" # ELo 1000
|
|
||||||
K12 = "Twelve Kyu"
|
|
||||||
K13 = "Thirteen Kyu"
|
|
||||||
K14 = "Fourteen Kyu"
|
|
||||||
K15 = "Fifteen Kyu"
|
|
||||||
K16 = "Sixteen Kyu" # Elo 500
|
|
||||||
K17 = "Seventeen Kyu"
|
|
||||||
K18 = "Eighteen Kyu"
|
|
||||||
K19 = "Nineteen Kyu"
|
|
||||||
K20 = "Twenty Kyu"
|
|
||||||
K21 = "Twenty-One Kyu" # Elo 0
|
|
||||||
K22 = "Twenty-Two Kyu"
|
|
||||||
K23 = "Twenty-Three Kyu"
|
|
||||||
K24 = "Twenty-Four Kyu"
|
|
||||||
K25 = "Twenty-Five Kyu"
|
|
||||||
K26 = "Twenty-Six Kyu" # Elo -500
|
|
||||||
K27 = "Twenty-Seven Kyu"
|
|
||||||
K28 = "Twenty-Eight Kyu"
|
|
||||||
K29 = "Twenty-Nine Kyu"
|
|
||||||
K30 = "Thirty Kyu" # Elo -900
|
|
||||||
UR = "Unknown Rank"
|
|
||||||
|
|
||||||
class User(db.Model):
|
class User(db.Model):
|
||||||
__tablename__ = "users"
|
__tablename__ = "users"
|
||||||
|
|
||||||
|
class Ranks(enum.Enum): # with minimal Elo rating
|
||||||
|
D7 = "Seven Dan" # Elo 2700+
|
||||||
|
D6 = "Six Dan"
|
||||||
|
D5 = "Five Dan" # Elo 2500
|
||||||
|
D4 = "Four Dan"
|
||||||
|
D3 = "Three Dan"
|
||||||
|
D2 = "Two Dan"
|
||||||
|
D1 = "One Dan"
|
||||||
|
K1 = "One Kyu" # Elo 2000
|
||||||
|
K2 = "Two Kyu"
|
||||||
|
K3 = "Three Kyu"
|
||||||
|
K4 = "Four Kyu"
|
||||||
|
K5 = "Five Kyu"
|
||||||
|
K6 = "Six Kyu" # Elo 1500
|
||||||
|
K7 = "Seven Kyu"
|
||||||
|
K8 = "Eight Kyu"
|
||||||
|
K9 = "Nine Kyu"
|
||||||
|
K10 = "Ten Kyu"
|
||||||
|
K11 = "Eleven Kyu" # ELo 1000
|
||||||
|
K12 = "Twelve Kyu"
|
||||||
|
K13 = "Thirteen Kyu"
|
||||||
|
K14 = "Fourteen Kyu"
|
||||||
|
K15 = "Fifteen Kyu"
|
||||||
|
K16 = "Sixteen Kyu" # Elo 500
|
||||||
|
K17 = "Seventeen Kyu"
|
||||||
|
K18 = "Eighteen Kyu"
|
||||||
|
K19 = "Nineteen Kyu"
|
||||||
|
K20 = "Twenty Kyu"
|
||||||
|
K21 = "Twenty-One Kyu" # Elo 0
|
||||||
|
K22 = "Twenty-Two Kyu"
|
||||||
|
K23 = "Twenty-Three Kyu"
|
||||||
|
K24 = "Twenty-Four Kyu"
|
||||||
|
K25 = "Twenty-Five Kyu"
|
||||||
|
K26 = "Twenty-Six Kyu" # Elo -500
|
||||||
|
K27 = "Twenty-Seven Kyu"
|
||||||
|
K28 = "Twenty-Eight Kyu"
|
||||||
|
K29 = "Twenty-Nine Kyu"
|
||||||
|
K30 = "Thirty Kyu" # Elo -900
|
||||||
|
UR = "Unknown Rank"
|
||||||
|
|
||||||
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
|
||||||
username = db.Column(db.String(255), unique=True, nullable=False, autoincrement=True)
|
username = db.Column(db.String(255), unique=True, nullable=False, autoincrement=True)
|
||||||
email = db.Column(db.String(255), unique=True, nullable=False)
|
email = db.Column(db.String(255), unique=True, nullable=False)
|
||||||
|
|
Loading…
Reference in a new issue