Skip to content

Commit

Permalink
Add tags + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nitko12 committed Feb 25, 2024
1 parent cd92c2b commit db06d34
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 29 deletions.
6 changes: 6 additions & 0 deletions backend/game/bots/bots.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ class Bots:
"resource_bot": ResourceBot
}

def list():
return [
{"name": bot_name}
for bot_name, bot_id in Bots.bots.items()
]

def exists(bot_id):
return bot_id in Bots.bots

Expand Down
2 changes: 1 addition & 1 deletion backend/routers/admin/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
router = APIRouter()


@router.get("/migrate")
@router.get("/migrate", tags=["admin"])
async def migrate():
await migration.drop_tables()
await migration.run_migrations()
Expand Down
8 changes: 5 additions & 3 deletions backend/routers/admin/bot.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from fastapi import APIRouter

from game.bots.bots import Bots

# BOT PATHS

# GET /admin/bot/list - [{"id": [id], "name": [name]}, {}, {}, {}]

router = APIRouter()


@router.get("/bot/list")
async def bot_list():
return {"message": "Hello World"}
@router.get("/bot/list", tags=["admin"])
def bot_list():
return Bots.list()
6 changes: 4 additions & 2 deletions backend/routers/admin/dataset.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from fastapi import APIRouter

from model.datasets import Datasets

# DATASET PATHS

# GET /admin/dataset/list - [{"id": [id], "name": [name]}, {}, {}, {}]

router = APIRouter()


@router.get("/dataset/list")
@router.get("/dataset/list", tags=["admin"])
async def dataset_list():
return {"message": "Hello World"}
return await Datasets.list()
10 changes: 5 additions & 5 deletions backend/routers/admin/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class EditGameParams(BaseModel):
tick_time: int


@router.post("/game/create")
@router.post("/game/create", tags=["admin"])
async def game_create(params: CreateGameParams):
Bots.validate_string(params.bots)

Expand Down Expand Up @@ -66,26 +66,26 @@ async def game_create(params: CreateGameParams):
return {"message": "success"}


@router.get("/game/list")
@router.get("/game/list", tags=["admin"])
async def game_list():
games = await Game.list()
return {"games": games}


@router.get("/game/{game_id}/player/list")
@router.get("/game/{game_id}/player/list", tags=["admin"])
async def player_list(game_id: int):
players = await Player.list(game_id=game_id)
return {"players": players}


@router.get("/game/{game_id}/delete")
@router.get("/game/{game_id}/delete", tags=["admin"])
async def game_delete(game_id: int):
# TODO ne baca exception ako je vec zavrsena
await Game.update(game_id=game_id, is_finished=True)
return {"message": "success"}


@router.post("/game/{game_id}/edit")
@router.post("/game/{game_id}/edit", tags=["admin"])
async def game_edit(game_id: int, params: EditGameParams):
if params.bots is not None:
Bots.validate_string(params.bots) # a:10;b:10;c:10;d:10
Expand Down
6 changes: 3 additions & 3 deletions backend/routers/admin/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,20 @@ def id_generator(size=8, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))


@router.post("/team/create")
@router.post("/team/create", tags=["admin"])
async def team_create(params: CreateTeam):
team_secret = id_generator()
team_id = await Team.create(team_name=params.team_name, team_secret=team_secret)

return {"team_id": team_id, "team_secret": team_secret}


@router.get("/team/list")
@router.get("/team/list", tags=["admin"])
async def team_list():
return await Team.list()


@router.get("/team/{team_id}/delete")
@router.get("/team/{team_id}/delete", tags=["admin"])
async def team_delete(team_id: int):
team_id = await Team.delete(team_id=team_id)

Expand Down
2 changes: 1 addition & 1 deletion backend/routers/users/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
router = APIRouter()


@router.get("/game/list")
@router.get("/game/list", tags=["users"])
async def game_list():
games = await Game.list()
return {"games": games}
12 changes: 6 additions & 6 deletions backend/routers/users/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
router = APIRouter()


@router.get("/game/{game_id}/market/offer/list")
@router.get("/game/{game_id}/market/offer/list", tags=["users"])
async def offer_list(game_id: int = Depends(game_id)):
return await Order.list(
game_id=game_id,
order_status=OrderStatus.ACTIVE.value
)


@router.get("/game/{game_id}/market/offer/prices/from/{start_tick}/to/{end_tick}")
@router.get("/game/{game_id}/market/offer/prices/from/{start_tick}/to/{end_tick}", tags=["users"])
async def offer_list(game_id: int = Depends(game_id), start_tick: int = 0, end_tick: int = 0):
if start_tick < 0 or end_tick < 0:
raise HTTPException(
Expand All @@ -41,7 +41,7 @@ class EnergyPrice(BaseModel):
price: int


@router.post("/game/{game_id}/player/{player_id}/market/energy/set_price")
@router.post("/game/{game_id}/player/{player_id}/market/energy/set_price", tags=["users"])
async def energy_set_price_player(price: EnergyPrice, game_id: int = Depends(game_id), player: int = Depends(player)):
if price <= 0:
raise HTTPException(
Expand All @@ -64,7 +64,7 @@ class UserOrder(BaseModel):
type: OrderType


@router.post("/game/{game_id}/player/{player_id}/market/offer/create")
@router.post("/game/{game_id}/player/{player_id}/market/offer/create", tags=["users"])
async def offer_create_player(order: UserOrder, game_id: int = Depends(game_id), player: int = Depends(player)):
if order.type == OrderType.ENERGY:
raise Exception(
Expand Down Expand Up @@ -92,7 +92,7 @@ async def offer_create_player(order: UserOrder, game_id: int = Depends(game_id),
return {"success": True}


@router.post("/game/{game_id}/player/{player_id}/market/offer/list")
@router.post("/game/{game_id}/player/{player_id}/market/offer/list", tags=["users"])
async def offer_list_player(game_id: int = Depends(game_id), player: int = Depends(player)):
return await Order.list(
game_id=game_id,
Expand All @@ -105,7 +105,7 @@ class OfferCancel(BaseModel):
ids: List[int]


@router.post("/game/{game_id}/player/{player_id}/market/offer/cancel")
@router.post("/game/{game_id}/player/{player_id}/market/offer/cancel", tags=["users"])
async def offer_cancel_player(body: OfferCancel, game_id: int = Depends(game_id), player: int = Depends(player)):
for order_id in body.ids:
await Order.update(
Expand Down
8 changes: 4 additions & 4 deletions backend/routers/users/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
router = APIRouter()


@router.get("/game/{game_id}/player/list")
@router.get("/game/{game_id}/player/list", tags=["users"])
async def player_list(game_id: int, team_id: int = Depends(team_id)):
players = await Player.list(game_id=game_id, team_id=team_id, is_active=True)
return {"players": players}
Expand All @@ -25,7 +25,7 @@ class PlayerCreate(BaseModel):
player_name: str = None


@router.post("/game/{game_id}/player/create")
@router.post("/game/{game_id}/player/create", tags=["users"])
async def player_create(game_id: int = Depends(game_id), team_id: int = Depends(team_id), player_name: str = None):
async with database.transaction():
if player_name is None:
Expand All @@ -37,11 +37,11 @@ async def player_create(game_id: int = Depends(game_id), team_id: int = Depends(
return {"player_id": player_id}


@router.get("/game/{game_id}/player/{player_id}")
@router.get("/game/{game_id}/player/{player_id}", tags=["users"])
async def player_get(player=Depends(player)):
return await Player.get(player_id=player.player_id)


@router.get("/game/{game_id}/player/{player_id}/delete")
@router.get("/game/{game_id}/player/{player_id}/delete", tags=["users"])
async def player_delete(player=Depends(player)):
return {"successfull": await Player.update(player_id=player.player_id, is_active=False)}
8 changes: 4 additions & 4 deletions backend/routers/users/power_plant.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
router = APIRouter(dependencies=[Depends(player)])


@router.get("/game/{game_id}/player/{player_id}/plant/list")
@router.get("/game/{game_id}/player/{player_id}/plant/list", tags=["users"])
async def list_plants(player_id: int):
player = await Player.get(player_id=player_id)

Expand All @@ -40,7 +40,7 @@ class PlantBuySell(BaseModel):
type: PowerPlantType


@router.post("/game/{game_id}/player/{player_id}/plant/buy")
@router.post("/game/{game_id}/player/{player_id}/plant/buy", tags=["users"])
async def buy_plant(player_id: int, plant: PlantBuySell):
type = PowerPlantType(plant.type)

Expand All @@ -56,7 +56,7 @@ async def buy_plant(player_id: int, plant: PlantBuySell):
await Player.update(player_id=player_id, **{type.name.lower() + "_plants_owned": plant_count + 1})


@router.post("/game/{game_id}/player/{player_id}/plant/sell")
@router.post("/game/{game_id}/player/{player_id}/plant/sell", tags=["users"])
async def sell_plant(player_id: int, plant: PlantBuySell):
type = PowerPlantType(plant.type)

Expand All @@ -73,7 +73,7 @@ class PowerOn(BaseModel):
number: int


@router.post("/game/{game_id}/player/{player_id}/plant/on")
@router.post("/game/{game_id}/player/{player_id}/plant/on", tags=["users"])
async def turn_on(player_id: int, plant: PowerOn):
async with database.transaction():
player = await Player.get(player_id=player_id)
Expand Down

0 comments on commit db06d34

Please sign in to comment.