uuid -> id

This commit is contained in:
Eden Kirin
2023-03-31 17:16:00 +02:00
parent 28a981980f
commit d45aca6c30
6 changed files with 103 additions and 21 deletions

View File

@ -24,8 +24,8 @@ from settings import settings
router = APIRouter()
def get_player(uuid: str, engine: GameEngine = Depends(get_game_engine)) -> Player:
player = engine.players.find(uuid)
def get_player(id: str, engine: GameEngine = Depends(get_game_engine)) -> Player:
player = engine.players.find(id)
if player is None:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND, detail="Player not found"
@ -76,7 +76,7 @@ async def start_game(
@router.get(
"/player/{uuid}",
"/player/{id}",
response_model=PlayerInfoResponseDto,
responses={
status.HTTP_403_FORBIDDEN: {
@ -85,7 +85,7 @@ async def start_game(
},
status.HTTP_404_NOT_FOUND: {
"model": ErrorResponseDto,
"description": " Player with uuid not found, probably kicked out",
"description": " Player with id not found, probably kicked out",
},
},
)
@ -96,7 +96,7 @@ async def get_player_info(
@router.post(
"/player/{uuid}/move/{direction}",
"/player/{id}/move/{direction}",
response_model=MovePlayerResponseDto,
status_code=status.HTTP_201_CREATED,
responses={
@ -110,7 +110,7 @@ async def get_player_info(
},
status.HTTP_404_NOT_FOUND: {
"model": ErrorResponseDto,
"description": " Player with uuid not found, probably kicked out",
"description": " Player with id not found, probably kicked out",
},
status.HTTP_409_CONFLICT: {
"model": ErrorResponseDto,
@ -157,24 +157,24 @@ async def get_products() -> GetProductsResponse:
)
@router.get("/products/{uuid}", response_model=ProductDto)
async def get_product(uuid: str) -> ProductDto:
@router.get("/products/{id}", response_model=ProductDto)
async def get_product(id: str) -> ProductDto:
for product in settings.products:
if product.uuid == uuid:
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/{uuid}/product/purchase")
@router.post("/player/{id}/product/purchase")
async def purchase_product(
body: PurchaseProductDto,
engine: GameEngine = Depends(get_game_engine),
player: Player = Depends(get_player),
):
for product in settings.products:
if product.uuid == body.product_uuid:
if product.id == body.product_id:
try:
await engine.purchase_product(player=player, product=product)
except PurchaseForbiddenForPlayer: