
from flask import Blueprint, render_template, request
import json

game = Blueprint('game', __name__)

from main import db
from models import SavedGame

@game.route('/')
def playGame():
    return render_template('game.html')

@game.route('/api/new', methods=['POST'])
def new():
    data = request.json
    name = data['name']
    gameState = json.dumps(data)

    game = SavedGame(name=name, gameState=gameState)

    db.session.add(game)
    db.session.commit()

    return json.dumps(game.id)

@game.route('/api/save', methods=['POST'])
def save():
    data = request.json
    gameID = data['id']
    gameState = data['game']
    gameToChange = SavedGame.query.filter_by(id=gameID).first()
    gameToChange.gameState = json.dumps(gameState)
    db.session.commit()
    db.session.remove()
    return 'Game saved.'

@game.route('/api/load', methods=['POST'])
def load():
    data = request.json
    game = SavedGame.query.filter_by(id=data).first()
    db.session.remove()
    return game.gameState

@game.route('/api/all', methods=['GET'])
def all():
    games = SavedGame.query.all()
    gameList = []
    for game in games:
        gameList.append({"id": game.id, "name": game.name})
    db.session.remove()
    return json.dumps(gameList)

@game.route('/api/delete', methods=['POST'])
def delete():
    gameID = request.json
    game = SavedGame.query.filter_by(id=gameID).first()
    db.session.delete(game)
    db.session.commit()
    db.session.remove()
    return 'Game deleted'
9708feb8e92fd3f39a32f5f50fc48301b3bd1c0f
<mask token>


@game.route('/')
def playGame():
    return render_template('game.html')


@game.route('/api/new', methods=['POST'])
def new():
    data = request.json
    name = data['name']
    gameState = json.dumps(data)
    game = SavedGame(name=name, gameState=gameState)
    db.session.add(game)
    db.session.commit()
    return json.dumps(game.id)


<mask token>


@game.route('/api/load', methods=['POST'])
def load():
    data = request.json
    game = SavedGame.query.filter_by(id=data).first()
    db.session.remove()
    return game.gameState


@game.route('/api/all', methods=['GET'])
def all():
    games = SavedGame.query.all()
    gameList = []
    for game in games:
        gameList.append({'id': game.id, 'name': game.name})
    db.session.remove()
    return json.dumps(gameList)


@game.route('/api/delete', methods=['POST'])
def delete():
    gameID = request.json
    game = SavedGame.query.filter_by(id=gameID).first()
    db.session.delete(game)
    db.session.commit()
    db.session.remove()
    return 'Game deleted'

<mask token>


@game.route('/')
def playGame():
    return render_template('game.html')


@game.route('/api/new', methods=['POST'])
def new():
    data = request.json
    name = data['name']
    gameState = json.dumps(data)
    game = SavedGame(name=name, gameState=gameState)
    db.session.add(game)
    db.session.commit()
    return json.dumps(game.id)


@game.route('/api/save', methods=['POST'])
def save():
    data = request.json
    gameID = data['id']
    gameState = data['game']
    gameToChange = SavedGame.query.filter_by(id=gameID).first()
    gameToChange.gameState = json.dumps(gameState)
    db.session.commit()
    db.session.remove()
    return 'Game saved.'


@game.route('/api/load', methods=['POST'])
def load():
    data = request.json
    game = SavedGame.query.filter_by(id=data).first()
    db.session.remove()
    return game.gameState


@game.route('/api/all', methods=['GET'])
def all():
    games = SavedGame.query.all()
    gameList = []
    for game in games:
        gameList.append({'id': game.id, 'name': game.name})
    db.session.remove()
    return json.dumps(gameList)


@game.route('/api/delete', methods=['POST'])
def delete():
    gameID = request.json
    game = SavedGame.query.filter_by(id=gameID).first()
    db.session.delete(game)
    db.session.commit()
    db.session.remove()
    return 'Game deleted'

<mask token>
game = Blueprint('game', __name__)
<mask token>


@game.route('/')
def playGame():
    return render_template('game.html')


@game.route('/api/new', methods=['POST'])
def new():
    data = request.json
    name = data['name']
    gameState = json.dumps(data)
    game = SavedGame(name=name, gameState=gameState)
    db.session.add(game)
    db.session.commit()
    return json.dumps(game.id)


@game.route('/api/save', methods=['POST'])
def save():
    data = request.json
    gameID = data['id']
    gameState = data['game']
    gameToChange = SavedGame.query.filter_by(id=gameID).first()
    gameToChange.gameState = json.dumps(gameState)
    db.session.commit()
    db.session.remove()
    return 'Game saved.'


@game.route('/api/load', methods=['POST'])
def load():
    data = request.json
    game = SavedGame.query.filter_by(id=data).first()
    db.session.remove()
    return game.gameState


@game.route('/api/all', methods=['GET'])
def all():
    games = SavedGame.query.all()
    gameList = []
    for game in games:
        gameList.append({'id': game.id, 'name': game.name})
    db.session.remove()
    return json.dumps(gameList)


@game.route('/api/delete', methods=['POST'])
def delete():
    gameID = request.json
    game = SavedGame.query.filter_by(id=gameID).first()
    db.session.delete(game)
    db.session.commit()
    db.session.remove()
    return 'Game deleted'

from flask import Blueprint, render_template, request
import json
game = Blueprint('game', __name__)
from main import db
from models import SavedGame


@game.route('/')
def playGame():
    return render_template('game.html')


@game.route('/api/new', methods=['POST'])
def new():
    data = request.json
    name = data['name']
    gameState = json.dumps(data)
    game = SavedGame(name=name, gameState=gameState)
    db.session.add(game)
    db.session.commit()
    return json.dumps(game.id)


@game.route('/api/save', methods=['POST'])
def save():
    data = request.json
    gameID = data['id']
    gameState = data['game']
    gameToChange = SavedGame.query.filter_by(id=gameID).first()
    gameToChange.gameState = json.dumps(gameState)
    db.session.commit()
    db.session.remove()
    return 'Game saved.'


@game.route('/api/load', methods=['POST'])
def load():
    data = request.json
    game = SavedGame.query.filter_by(id=data).first()
    db.session.remove()
    return game.gameState


@game.route('/api/all', methods=['GET'])
def all():
    games = SavedGame.query.all()
    gameList = []
    for game in games:
        gameList.append({'id': game.id, 'name': game.name})
    db.session.remove()
    return json.dumps(gameList)


@game.route('/api/delete', methods=['POST'])
def delete():
    gameID = request.json
    game = SavedGame.query.filter_by(id=gameID).first()
    db.session.delete(game)
    db.session.commit()
    db.session.remove()
    return 'Game deleted'


from flask import Blueprint, render_template, request
import json

game = Blueprint('game', __name__)

from main import db
from models import SavedGame

@game.route('/')
def playGame():
    return render_template('game.html')

@game.route('/api/new', methods=['POST'])
def new():
    data = request.json
    name = data['name']
    gameState = json.dumps(data)

    game = SavedGame(name=name, gameState=gameState)

    db.session.add(game)
    db.session.commit()

    return json.dumps(game.id)

@game.route('/api/save', methods=['POST'])
def save():
    data = request.json
    gameID = data['id']
    gameState = data['game']
    gameToChange = SavedGame.query.filter_by(id=gameID).first()
    gameToChange.gameState = json.dumps(gameState)
    db.session.commit()
    db.session.remove()
    return 'Game saved.'

@game.route('/api/load', methods=['POST'])
def load():
    data = request.json
    game = SavedGame.query.filter_by(id=data).first()
    db.session.remove()
    return game.gameState

@game.route('/api/all', methods=['GET'])
def all():
    games = SavedGame.query.all()
    gameList = []
    for game in games:
        gameList.append({"id": game.id, "name": game.name})
    db.session.remove()
    return json.dumps(gameList)

@game.route('/api/delete', methods=['POST'])
def delete():
    gameID = request.json
    game = SavedGame.query.filter_by(id=gameID).first()
    db.session.delete(game)
    db.session.commit()
    db.session.remove()
    return 'Game deleted'