Purchase product return
This commit is contained in:
@ -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(
|
async def purchase_product(
|
||||||
body: PurchaseProductDto,
|
body: PurchaseProductDto,
|
||||||
engine: GameEngine = Depends(get_game_engine),
|
engine: GameEngine = Depends(get_game_engine),
|
||||||
player: Player = Depends(get_player),
|
player: Player = Depends(get_player),
|
||||||
):
|
) -> ProductDto:
|
||||||
for product in settings.products:
|
for product in settings.products:
|
||||||
if product.id == body.product_id:
|
if product.id == body.product_id:
|
||||||
try:
|
try:
|
||||||
await engine.purchase_product(player=player, product=product)
|
await engine.purchase_product(player=player, product=product)
|
||||||
|
return ProductDto.from_orm(product)
|
||||||
except PurchaseForbiddenForPlayer:
|
except PurchaseForbiddenForPlayer:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_403_FORBIDDEN,
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
detail="Purchase forbidden for this player",
|
detail="Purchase forbidden for this player",
|
||||||
)
|
)
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_404_NOT_FOUND, detail="Product not found"
|
status_code=status.HTTP_404_NOT_FOUND, detail="Product not found"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user