Purchase product return

This commit is contained in:
Eden Kirin
2023-04-10 20:03:15 +02:00
parent d4d03b78f9
commit 9425e0fff0

View File

@ -167,23 +167,22 @@ async def get_product(id: str) -> ProductDto:
)
@router.post("/player/{id}/product/purchase")
@router.post("/player/{id}/product/purchase", response_model=ProductDto)
async def purchase_product(
body: PurchaseProductDto,
engine: GameEngine = Depends(get_game_engine),
player: Player = Depends(get_player),
):
) -> ProductDto:
for product in settings.products:
if product.id == body.product_id:
try:
await engine.purchase_product(player=player, product=product)
return ProductDto.from_orm(product)
except PurchaseForbiddenForPlayer:
raise HTTPException(
status_code=status.HTTP_403_FORBIDDEN,
detail="Purchase forbidden for this player",
)
break
else:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Product not found"
)
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Product not found"
)