Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add order type limit per player and resource #66

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion backend/routers/users/market.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ async def order_list(game: Game = Depends(game_dep)) -> List[OrderResponse]:


@router.get("/game/{game_id}/player/{player_id}/orders")
async def order_list_player(game: Game = Depends(game_dep),
async def order_list_player(game: Game = Depends(game_dep),
player: Player = Depends(player_dep)) -> List[OrderResponse]:
return await Order.list(
game_id=game.game_id,
Expand All @@ -105,6 +105,26 @@ class UserOrder(BaseModel):
async def order_create_player(order: UserOrder,
game: Game = Depends(game_dep),
player: Player = Depends(player_dep)) -> SuccessfulResponse:

# max 10 orders at a time of type ACTIVE, PENDING, IN_QUEUE
total_orders_not_processed = await Order.count(
game_id=game.game_id,
player_id=player.player_id,
order_status=OrderStatus.ACTIVE.value
) + await Order.count(
game_id=game.game_id,
player_id=player.player_id,
order_status=OrderStatus.PENDING.value
) + await Order.count(
game_id=game.game_id,
player_id=player.player_id,
order_status=OrderStatus.IN_QUEUE.value
)

if total_orders_not_processed >= 10:
raise HTTPException(
status_code=400, detail="Maximum 10 orders can be active at a time")

if order.resource == Resource.ENERGY:
raise HTTPException(
status_code=400,
Expand Down
Loading