Skip to content

Card

scooze.routers.card

card_root() -> CardModel async

Get a random card from the database.

Returns:

Type Description
CardModel

A random card from the database.

Raises:

Type Description
HTTPException

404 - No cards found in the database.

add_card(card_data: CardModelData) -> CardModel async

Add a card to the database.

Parameters:

Name Type Description Default
card_data CardModelData

A dict conforming to CardModelData's schema.

required

Returns:

Type Description
CardModel

The created card.

Raises:

Type Description
HTTPException

400 - Create failed, passes along the error message.

get_card_by_id(card_id: PydanticObjectId = Depends(_validate_card_id)) -> CardModel async

Get the card with the given ID.

Parameters:

Name Type Description Default
card_id PydanticObjectId

The ID of the card to get.

Depends(_validate_card_id)

Returns:

Type Description
CardModel

The requested card.

Raises:

Type Description
HTTPException

404 - Card wasn't found.

HTTPException

422 - Bad ID given.

get_card_by_name(card_name: str) -> CardModel async

Get a card by its name.

If more than 1 version of the card is present, returns the first one found.

Parameters:

Name Type Description Default
card_name str

The name of the card to get.

required

Returns:

Type Description
CardModel

The requested card.

Raises:

Type Description
HTTPException

404 - Card wasn't found.

update_card(card_req: CardModel, card_id: PydanticObjectId = Depends(_validate_card_id)) -> CardModel async

Update an existing card with the given scooze ID and payload.

Fields will be updated according to the given payload. If a field is not present in the payload, it will not be updated.

Parameters:

Name Type Description Default
card_id PydanticObjectId

The ID of the card to update.

Depends(_validate_card_id)
card_req CardModel

The fields to update.

required

Returns:

Type Description
CardModel

The updated card.

Raises:

Type Description
HTTPException

404 - Card wasn't found, pre-update.

HTTPException

404 - Card wasn't found, post-update.

HTTPException

422 - Bad ID given.

delete_card_by_id(card_id: PydanticObjectId = Depends(_validate_card_id)) -> JSONResponse async

Delete an existing card with the given ID.

Parameters:

Name Type Description Default
card_id PydanticObjectId

The ID of the card to delete.

Depends(_validate_card_id)

Returns:

Type Description
JSONResponse

A message that either the card was deleted or not deleted.

Raises:

Type Description
HTTPException

400 - Card wasn't deleted.

HTTPException

404 - Card wasn't found.

HTTPException

422 - Bad ID given.

scooze.routers.cards

cards_root(limit: int = 3) -> list[CardModel] async

Get random cards from the database.

Parameters:

Name Type Description Default
limit int

The maximum number of cards to get.

3

Returns:

Type Description
list[CardModel]

Random cards from the database.

Raises:

Type Description
HTTPException

404 - No cards found in the database.

add_cards(cards: list[CardModelData]) -> JSONResponse async

Add a list of cards to the database.

Parameters:

Name Type Description Default
cards list[CardModelData]

A list of dicts conforming to CardModelData's schema.

required

Returns:

Type Description
JSONResponse

A message stating how many cards were created.

Raises:

Type Description
HTTPException

400 - Create failed, passes along the error message.

get_cards_by(property_name: str, values: list[Any], paginated: bool = False, page: int = 1, page_size: int = 10) -> list[CardModel] async

Get cards where the given property matches any of the given values.

Parameters:

Name Type Description Default
property_name str

The property to check against.

required
values list[Any]

Matching values for the given property.

required
paginated bool

Return paginated results if True, or all matches if False.

False
page int

The page to return matches from.

1
page_size int

The number of results per page.

10

Returns:

Type Description
list[CardModel]

A list of cards matching the search criteria.

Raises:

Type Description
HTTPException

404 - Cards weren't found.

delete_cards_all() -> JSONResponse async

Deletes all cards in the database.

Returns:

Type Description
JSONResponse

A message that the cards were deleted.

Raises:

Type Description
HTTPException

400 - Cards weren't deleted.