|
@@ -3,7 +3,7 @@ import uuid
|
|
|
|
|
|
from flask import Blueprint, session, abort, request, current_app, jsonify
|
|
from flask import Blueprint, session, abort, request, current_app, jsonify
|
|
|
|
|
|
-from db import db, Game
|
|
|
|
|
|
+from db import db, Game, CoordSet, GuessSet
|
|
from lib import generate_coord
|
|
from lib import generate_coord
|
|
|
|
|
|
game = Blueprint("game", __name__)
|
|
game = Blueprint("game", __name__)
|
|
@@ -17,12 +17,17 @@ def require_name():
|
|
|
|
|
|
|
|
|
|
def require_game(game_id):
|
|
def require_game(game_id):
|
|
- g = Game.get(game_id)
|
|
|
|
|
|
+ g = Game.query.get(game_id)
|
|
if g is None:
|
|
if g is None:
|
|
abort(404)
|
|
abort(404)
|
|
return g
|
|
return g
|
|
|
|
|
|
|
|
|
|
|
|
+def new_coord_string():
|
|
|
|
+ lat, lng = generate_coord(current_app.config["GOOGLE_API_KEY"])
|
|
|
|
+ return f"{lat},{lng}"
|
|
|
|
+
|
|
|
|
+
|
|
@game.route("", methods=["PUT"])
|
|
@game.route("", methods=["PUT"])
|
|
def create_game():
|
|
def create_game():
|
|
name = require_name()
|
|
name = require_name()
|
|
@@ -31,17 +36,25 @@ def create_game():
|
|
abort(400)
|
|
abort(400)
|
|
|
|
|
|
game_id = str(uuid.uuid4())
|
|
game_id = str(uuid.uuid4())
|
|
- while Game.get(game_id) is not None:
|
|
|
|
|
|
+ while Game.query.get(game_id) is not None:
|
|
# basically impossible collision, but let's be safe
|
|
# basically impossible collision, but let's be safe
|
|
game_id = str(uuid.uuid4())
|
|
game_id = str(uuid.uuid4())
|
|
|
|
|
|
- coords = [generate_coord(current_app.config["GOOGLE_API_KEY"]) for _ in range(5)]
|
|
|
|
- print(coords) # TODO
|
|
|
|
|
|
+ cs = CoordSet(
|
|
|
|
+ coord_1=new_coord_string(),
|
|
|
|
+ coord_2=new_coord_string(),
|
|
|
|
+ coord_3=new_coord_string(),
|
|
|
|
+ coord_4=new_coord_string(),
|
|
|
|
+ coord_5=new_coord_string()
|
|
|
|
+ )
|
|
|
|
+ db.session.add(cs)
|
|
|
|
+ db.session.commit()
|
|
|
|
|
|
new_game = Game(
|
|
new_game = Game(
|
|
game_id=game_id,
|
|
game_id=game_id,
|
|
timer=timer,
|
|
timer=timer,
|
|
- creator=name
|
|
|
|
|
|
+ creator=name,
|
|
|
|
+ coord_set=cs
|
|
)
|
|
)
|
|
db.session.add(new_game)
|
|
db.session.add(new_game)
|
|
db.session.commit()
|
|
db.session.commit()
|
|
@@ -59,7 +72,7 @@ def game_settings(game_id):
|
|
"gameId": g.game_id,
|
|
"gameId": g.game_id,
|
|
"creator": g.creator,
|
|
"creator": g.creator,
|
|
"timer": g.timer,
|
|
"timer": g.timer,
|
|
- "coords": {}, # TODO
|
|
|
|
|
|
+ "coords": g.coord_set.to_dict(),
|
|
"guesses": [], # TODO
|
|
"guesses": [], # TODO
|
|
})
|
|
})
|
|
|
|
|