From efd7476321cd4781823804ed9448f198d11ae843 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nitko=20Nitki=C4=87?= Date: Fri, 1 Mar 2024 21:09:31 +0100 Subject: [PATCH] Add order type limit per player and resource --- backend/routers/users/market.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/backend/routers/users/market.py b/backend/routers/users/market.py index 989ac66..a9d79a9 100644 --- a/backend/routers/users/market.py +++ b/backend/routers/users/market.py @@ -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, @@ -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,