Hello,
I wanted to know if it's possible to create a single endpoint that will perform the get of the entity by either an id or a slug?
I can see that the path parameter of the get endpoint can take a sequence of str as path (so maybe it was intendend to work like that)
This is working fine for the moment, but the thing is that I would like all subsequent routes to take as parent parent parameter either an id or the slug of the competition.
# Endpoint by ID
@get(
operation_id="GetCompetition",
name="competitions:get",
path=urls.COMPETITION_DETAIL,
summary="Retrieve the details of a competition.",
)
async def get_competition(
self,
competitions_service: CompetitionService,
competition_id: Annotated[
UUID,
Parameter(
title="Competition ID",
description="The competition to retrieve.",
),
],
) -> Competition:
"""Get a competition."""
db_obj = await competitions_service.get(competition_id)
return competitions_service.to_schema(db_obj, schema_type=Competition)
# Endpoint by slug
@get(
operation_id="GetCompetitionBySlug",
name="competitions:get-by-slug",
path=urls.COMPETITION_DETAIL_SLUG,
summary="Retrieve the details of a competition from a slug.",
)
async def get_competition_by_slug(
self,
competitions_service: CompetitionService,
competition_slug: Annotated[
str,
Parameter(
title="Competition Slug",
description="The competition to retrieve.",
),
],
) -> Competition:
"""Get a competition."""
db_obj = await competitions_service.get(item_id=competition_slug, id_attribute="slug")
return competitions_service.to_schema(db_obj, schema_type=Competition)
Thanks