def setUp(self): super().setUp() db_actions.crud( action="create", model=models.Campaign, data={ "name": "Test Campaign 1", "description": "Test Description 1", "time_of_day": "07:30", "day": 1, "user_id": 1 }, params=["id"] ) db_actions.crud( action="create", model=models.Campaign, data={ "name": "Test Campaign 2", "description": "Test Description 2", "time_of_day": "07:30", "day": 1, "user_id": 1 }, params=["id"] )
def setUp(self): super().setUp() db_actions.crud(action="create", model=models.Player, data={ "name": "Test Player 1", "experience": 0, "level": 1, "health": 10, "current_health": 10, "carry_capacity": 10, "user_id": 1 }, params=["id"]) db_actions.crud(action="create", model=models.Player, data={ "name": "Test Player 2", "experience": 0, "level": 1, "health": 10, "current_health": 10, "carry_capacity": 10, "user_id": 1 }, params=["id"])
def setUp(self): super().setUp() db_actions.crud( action="create", model=models.Enemy, data={"name": "Test Enemy 1", "level": 1, "user_id": 1}, params=["id"] ) db_actions.crud( action="create", model=models.Enemy, data={"name": "Test Enemy 2", "level": 2, "user_id": 1}, params=["id"] )
def add_battle_enemy() -> tuple: data = request.json battle_enemy, status = db_actions.crud(action="create", model=models.BattleEnemy, data=data, params=["battle_id", "enemy_id"]) return jsonify(battle_enemy), status
def get_user() -> tuple: user, status = db_actions.crud(action="read", model=models.User, query={ "id": current_identity.id, }) return jsonify(user), status
def add_player_item() -> tuple: data = request.json player_item, status = db_actions.crud(action="create", model=models.PlayerItem, data=data, params=["player_id", "item_id"]) return jsonify(player_item), status
def get_campaign_battle(campaign_id: int, battle_id: int) -> tuple: campaign_battle, status = db_actions.crud(action="read", model=models.CampaignBattle, query={ "campaign_id": campaign_id, "battle_id": battle_id }) return jsonify(campaign_battle), status
def add_enemy() -> tuple: data = request.json data["user_id"] = current_identity.id enemy, status = db_actions.crud(action="create", model=models.Enemy, data=data, params=["id"]) return jsonify(enemy), status
def get_enemy(_id: int) -> tuple: enemy, status = db_actions.crud(action="read", model=models.Enemy, query={ "id": _id, "user_id": current_identity.id }) return jsonify(enemy), status
def delete_player_item(player_id: int, item_id: int) -> tuple: result, status = db_actions.crud(action="delete", model=models.PlayerItem, query={ "player_id": player_id, "item_id": item_id }) return jsonify(result), status
def delete_battle_enemy(battle_id: int, enemy_id: int) -> tuple: result, status = db_actions.crud(action="delete", model=models.BattleEnemy, query={ "battle_id": battle_id, "enemy_id": enemy_id }) return jsonify(result), status
def delete_campaign_battle(campaign_id: int, battle_id: int) -> tuple: result, status = db_actions.crud(action="delete", model=models.CampaignBattle, query={ "campaign_id": campaign_id, "battle_id": battle_id }) return jsonify(result), status
def get_battle_enemy(battle_id: int, enemy_id: int) -> tuple: battle_enemy, status = db_actions.crud(action="read", model=models.BattleEnemy, query={ "battle_id": battle_id, "enemy_id": enemy_id }) return jsonify(battle_enemy), status
def delete_campaign_player(campaign_id: int, player_id: int) -> tuple: result, status = db_actions.crud(action="delete", model=models.CampaignPlayer, query={ "campaign_id": campaign_id, "player_id": player_id }) return jsonify(result), status
def add_item() -> tuple: data = request.json data["user_id"] = current_identity.id item, status = db_actions.crud(action="create", model=models.Item, data=data, params=["id"]) return jsonify(item), status
def get_item(_id: int) -> tuple: item, status = db_actions.crud(action="read", model=models.Item, query={ "id": _id, "user_id": current_identity.id }) return jsonify(item), status
def get_items() -> tuple: items, status = db_actions.crud(action="list", model=models.Item, query={ **request.args, "user_id": current_identity.id }) return jsonify(items), status
def get_campaign_player(campaign_id: int, player_id: int) -> tuple: campaign_player, status = db_actions.crud(action="read", model=models.CampaignPlayer, query={ "campaign_id": campaign_id, "player_id": player_id }) return jsonify(campaign_player), status
def get_player_item(player_id: int, item_id: int) -> tuple: player_item, status = db_actions.crud(action="read", model=models.PlayerItem, query={ "player_id": player_id, "item_id": item_id }) return jsonify(player_item), status
def add_campaign_player() -> tuple: data = request.json campaign_player, status = db_actions.crud( action="create", model=models.CampaignPlayer, data=data, params=["campaign_id", "player_id"]) return jsonify(campaign_player), status
def add_campaign_battle() -> tuple: data = request.json campaign_battle, status = db_actions.crud( action="create", model=models.CampaignBattle, data=data, params=["campaign_id", "battle_id"]) return jsonify(campaign_battle), status
def get_enemies() -> tuple: enemies, status = db_actions.crud(action="list", model=models.Enemy, query={ **request.args, "user_id": current_identity.id }) return jsonify(enemies), status
def enemies_in_battle(_id: int) -> tuple: enemies, status = db_actions.crud( action="list", model=models.BattleEnemy, query={ "battle_id": _id } ) if status == 200: enemies, status = db_actions.crud( action="list", model=models.Enemy, query={ "ids": [enemy["enemy_id"] for enemy in enemies] } ) return jsonify(enemies), status
def battles_in_campaign(_id: int) -> tuple: battles, status = db_actions.crud( action="list", model=models.CampaignBattle, query={ "campaign_id": _id } ) if status == 200: battles, status = db_actions.crud( action="list", model=models.Battle, query={ "ids": [battle["battle_id"] for battle in battles] } ) return jsonify(battles), status
def items_of_player(_id: int) -> tuple: items, status = db_actions.crud( action="list", model=models.PlayerItem, query={ "player_id": _id } ) if status == 200: items, status = db_actions.crud( action="list", model=models.Item, query={ "ids": [item["item_id"] for item in items] } ) return jsonify(items), status
def delete_battles(_id: int) -> dict: db_actions.crud( action="read", model=models.Battle, query={ "id": _id, "user_id": current_identity.id } ) db_actions.crud( action="delete_many", model=models.BattleEnemy, query={ "battle_id": _id } ) db_actions.crud( action="delete_many", model=models.CampaignBattle, query={ "battle_id": _id } ) result, status = db_actions.crud( action="delete", model=models.Battle, query={ "id": _id, } ) return jsonify(result)
def delete_campaign(_id: int) -> tuple: db_actions.crud( action="read", model=models.Campaign, query={ "id": _id, "user_id": current_identity.id } ) db_actions.crud( action="delete_many", model=models.CampaignPlayer, query={ "campaign_id": _id, } ) db_actions.crud( action="delete_many", model=models.CampaignBattle, query={ "campaign_id": _id, } ) result, status = db_actions.crud( action="delete", model=models.Campaign, query={ "id": _id, } ) return jsonify(result), status
def add_user() -> tuple: data = request.json m = hashlib.md5(f"{data['password']}{settings.SALT}".encode("utf-8")) data["password"] = m.hexdigest() user, status = db_actions.crud(action="create", model=models.User, data=data, params=["id"]) return jsonify(user), status
def add_player() -> tuple: data = request.json data["user_id"] = current_identity.id player, status = db_actions.crud(action="create", model=models.Player, data=data, params=["id"]) player = fill_items(player) return jsonify(player), status
def get_player(_id: int) -> tuple: player, status = db_actions.crud(action="read", model=models.Player, query={ "id": _id, "user_id": current_identity.id }) player = fill_items(player) return jsonify(player), status