uuid -> id
This commit is contained in:
@ -27,7 +27,7 @@ class PositionDto(BaseModel):
|
||||
|
||||
|
||||
class PlayerDto(BaseModel):
|
||||
uuid: str
|
||||
id: str
|
||||
name: str
|
||||
active: bool
|
||||
position: PositionDto
|
||||
@ -42,7 +42,7 @@ class DestinationDto(BaseModel):
|
||||
|
||||
class ProductDto(BaseModel):
|
||||
name: str
|
||||
uuid: str
|
||||
id: str
|
||||
description: Optional[str] = None
|
||||
|
||||
class StartGameRequestDto(BaseModel):
|
||||
@ -75,4 +75,4 @@ class GetProductsResponse(BaseModel):
|
||||
|
||||
|
||||
class PurchaseProductDto(BaseModel):
|
||||
product_uuid: str
|
||||
product_id: str
|
||||
|
||||
@ -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:
|
||||
|
||||
Reference in New Issue
Block a user