Add endpoint to get all event categories
This commit is contained in:
parent
1a3cca9712
commit
b0bbc7e81a
|
@ -125,6 +125,22 @@ async def get_user_categories(user_id: PydanticObjectId, user: CurrentUserDep) -
|
||||||
return [CategoryData.from_category(category) for category in categories]
|
return [CategoryData.from_category(category) for category in categories]
|
||||||
|
|
||||||
|
|
||||||
|
@base_router.get("/events/{event_id}/categories")
|
||||||
|
async def get_event_categories(event_id: PydanticObjectId, user: CurrentUserDep) -> list[CategoryData]:
|
||||||
|
"""Get all categories that belong to given event."""
|
||||||
|
event = await Event.get(event_id, fetch_links=True)
|
||||||
|
if event is None:
|
||||||
|
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Event with given id doesn't exist")
|
||||||
|
|
||||||
|
if cast(User, event.user).id != user.id:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_403_FORBIDDEN,
|
||||||
|
detail="You can only access your own events",
|
||||||
|
)
|
||||||
|
|
||||||
|
return [CategoryData.from_category(category) for category in cast(list[Category], event.categories)]
|
||||||
|
|
||||||
|
|
||||||
@categories_router.get("{category_id}")
|
@categories_router.get("{category_id}")
|
||||||
async def get_category(category_id: PydanticObjectId, user: CurrentUserDep) -> CategoryData:
|
async def get_category(category_id: PydanticObjectId, user: CurrentUserDep) -> CategoryData:
|
||||||
"""Get a category by ID."""
|
"""Get a category by ID."""
|
||||||
|
|
Loading…
Reference in a new issue