Drop old purchase views and models
This commit is contained in:
@ -6,12 +6,9 @@ from hopper.api.dto import (
|
||||
DestinationDto,
|
||||
ErrorResponseDto,
|
||||
GameInfoDto,
|
||||
GetProductsResponse,
|
||||
MovePlayerResponseDto,
|
||||
PingResponse,
|
||||
PlayerInfoResponseDto,
|
||||
ProductDto,
|
||||
PurchaseProductDto,
|
||||
StartGameRequestDto,
|
||||
StartGameResponseDto,
|
||||
)
|
||||
@ -21,10 +18,8 @@ from hopper.errors import (
|
||||
Collision,
|
||||
GameLockForMovement,
|
||||
PositionOutOfBounds,
|
||||
PurchaseForbiddenForPlayer,
|
||||
)
|
||||
from hopper.models.player import Player
|
||||
from settings import settings
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@ -153,58 +148,3 @@ async def move_player(
|
||||
response.status_code = status.HTTP_200_OK
|
||||
|
||||
return MovePlayerResponseDto(player=player)
|
||||
|
||||
|
||||
@router.get("/products", response_model=GetProductsResponse)
|
||||
async def get_products() -> GetProductsResponse:
|
||||
return GetProductsResponse(
|
||||
products=settings.products,
|
||||
)
|
||||
|
||||
|
||||
@router.get("/products/{id}", response_model=ProductDto)
|
||||
async def get_product(id: str) -> ProductDto:
|
||||
for product in settings.products:
|
||||
if product.id == id:
|
||||
return ProductDto.from_orm(product)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Product not found"
|
||||
)
|
||||
|
||||
|
||||
@router.post(
|
||||
"/player/{id}/product/purchase",
|
||||
response_model=ProductDto,
|
||||
responses={
|
||||
status.HTTP_200_OK: {
|
||||
"model": ProductDto,
|
||||
"description": "Product purchased",
|
||||
},
|
||||
status.HTTP_403_FORBIDDEN: {
|
||||
"model": ErrorResponseDto,
|
||||
"description": "Purchase forbidden for this player",
|
||||
},
|
||||
status.HTTP_404_NOT_FOUND: {
|
||||
"model": ErrorResponseDto,
|
||||
"description": " Player with id not found, probably kicked out",
|
||||
},
|
||||
},
|
||||
)
|
||||
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",
|
||||
)
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_404_NOT_FOUND, detail="Product not found"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user