def get_game(_id=""): if _id: game = get_game_from_es(_id) return jsonify(**game), 200, None games = get_game_from_es() return jsonify(**{"data":games}), 200, None
def join_game(): user_id = request.args.get("user_id") game_id = request.args.get("game_id") if not user_id or not game_id: raise Exception("must supply 'user_id' and 'game_id'") print user_id, game_id game = get_game_from_es(game_id) participents = game.get('participents_ids',[]) participents.append(user_id) game['participents_ids'] = sorted(list(set(participents))) update_game(game) return jsonify(**game), 200, None
def update_game(_id=""): data = request.data if request.form: data = request.form.keys()[0] data = json.loads(data) if not _id: _id = data['id'] if not _id: raise Exception("failed to get the id. must supply id as path or in body") game = get_game_from_es(_id) game.update(data) game = es.index(index="games", doc_type="game", body=game, id=_id) return jsonify(**game), 200, None