def put(self, game_id): data = request.get_json() db_play = DbGame(DbConfig()) res = db_play.update_game(data, game_id) if res[1] is not None: return make_response(jsonify({"error": res[1]}), 400) else: return make_response(jsonify(res), 204)
def patch(self): """The filters are in the body """ data = request.get_json() db_play = DbGame(DbConfig()) res = db_play.get_games(data) if res[1] is not None: return make_response(jsonify({"error": res[1]}), 400) return make_response(jsonify(res), 200)
def get(self, game_id): """this get the game inclusing the plays and the tabels """ db_play = DbGame(DbConfig()) res = db_play.get_game_plays(game_id) if res[1] is not None: return make_response(jsonify({"error": res[1]}), 400) else: return make_response(jsonify(res), 200)
def delete(self, user_id): obj = {"is_deprecated": True} db_user = DbUser(DbConfig()) res = db_user.put_user(obj, user_id) is_success = res[1] is None response = make_response(jsonify({"error": res[1]}), 204 if is_success else 400) return response
def users_ids(): print("setup") db_config_instance = DbConfig() db_play = DbGame(db_config_instance) res = db_play.get_query("select * from public.users limit 100") assert res[1] == None assert len(res[0][0]) > 2 limit = min(len(res[0]), 100) id = random.randint(0, limit - 2) user1 = res[0][id][0] user2 = res[0][id + 1][0] yield (user1, user2) print("teardown")
def patch(self, game_id, user_id): data = request.get_json() if "column_name" not in data or "row_name" not in data or "value" not in data: return make_response( jsonify({ "error": "invalid payload (column_name,row_name and value properties are mandatory" }), 400) db_play = DbGame(DbConfig()) res = db_play.update_tabel(data["column_name"], data["row_name"], game_id, user_id, data["value"]) if res[1] is not None: return make_response(jsonify({"error": res[1]}), 400) else: return make_response(jsonify(res), 204)
def post(self): data = request.get_json() # status code parser = reqparse.RequestParser() parser.add_argument('type', help='detail or summary') #parser.add_argument('year',type=int, help='detail or summary') #args = parser.parse_args() # db_user = db_user = DbUser(DbConfig()) res_val = db_user.post_user(data) ret_body = {"id": res_val[0]} if not res_val[0]: ret_body["error"] = res_val[1] response = make_response(jsonify(ret_body), 201 if res_val[0] else 400) response.headers['X-Parachutes'] = 'parachutes are cool' return response
def put(self, user_id): req_body = request.get_json() # status code need_fetch = False if "fetch" not in request.values else request.values[ "fetch"].lower() == "true" db_user = DbUser(DbConfig()) res_val_db = db_user.put_user(req_body, user_id) is_success = res_val_db[1] is None res_body = {"success": is_success} if not is_success: res_body["error"] = res_val_db[1] if need_fetch and is_success: return self.get(user_id) response = make_response(jsonify(res_body), 204 if is_success else 400) #response.headers['X-Parachutes'] = 'parachutes are cool' return response
def get(self): args = request.args print(args) db_user = DbUser(DbConfig()) if "filters" in args and args["filters"].lower() == "true": data = request.get_json() if "email_address" in data: res_val_db = db_user.get_user(email=data["email_address"]) else: limit = 100 if "limit" not in args else int(args["limit"]) offset = 0 if "offset" not in args else int(args["offset"]) order_by = "first_name" if "orderby" not in args else str( args["orderby"]) res_val_db = db_user.get_users(order_by, limit, offset) if res_val_db[1] is not None: return make_response(jsonify({"error": res_val_db[1]}), 400) response = make_response(jsonify(res_val_db[0]), 200) return response
def post(self): """body fata would lokk like this {"game_name": "this is new game Oct00", "comment": "this is a comment" ,"users" : [{{user_id}},{{user_id2}}]} """ data = request.get_json() if data is None or "game_name" not in data: return make_response( jsonify({ "error": "payload is missing or doesn not have a 'game_name' properti" }), 400) if "users" not in data or not isinstance(data["users"], list) or len( data["users"]) == 0: return make_response( jsonify({ "error": "'users' array property from payload id missing or not properly setup" }), 400) db_play = DbGame(DbConfig()) res = db_play.new_game( game_name=data["game_name"], game_comments=None if "comment" not in data else data["comment"]) if res[1] is not None: return make_response(jsonify({"error": res[1]}), 400) game_id = int(res[0]) if game_id > 0: res = db_play.new_play(data["users"], game_id) if res[1] is not None: return make_response(jsonify({"error": res[1]}), 400) return make_response( jsonify({ "game_id": game_id, "users": res[0] }), 201) else: return make_response(jsonify({"error": "game not created"}), 400)
def get(self, user_id): db_user = DbUser(DbConfig()) res_val_db = db_user.get_user(userid=user_id) response = make_response(jsonify({"response": res_val_db}), 200) return response
def db(): print("setup") db_config_instance = DbConfig() db_exec = DbExecuter(db_config_instance) yield db_exec print("teardown")
def db_val(): print("setup") db_config_instance = DbConfig() db_user = DbUser(db_config_instance) yield db_user print("teardown")
def db_play(): print("setup") db_config_instance = DbConfig() db_play = DbGame(db_config_instance) yield db_play print("teardown")