fix reponse model
This commit is contained in:
@@ -31,7 +31,7 @@ class Event(BaseModel):
|
||||
|
||||
|
||||
class EventOut(BaseModel):
|
||||
id: ObjectIdField = None
|
||||
id: str | None = None
|
||||
name: str
|
||||
place: str
|
||||
description: str
|
||||
@@ -43,6 +43,23 @@ class EventOut(BaseModel):
|
||||
end_date: datetime | None = None
|
||||
tags: list[str] = []
|
||||
|
||||
@classmethod
|
||||
def from_mongo(cls, event: Event) -> "EventOut":
|
||||
return cls(
|
||||
id=str(event.id) if event.id else None,
|
||||
name=event.name,
|
||||
place=event.place,
|
||||
description=event.description,
|
||||
imgUrl=event.imgUrl,
|
||||
link=event.link,
|
||||
ticket=event.ticket,
|
||||
status=event.status,
|
||||
start_date=event.start_date,
|
||||
end_date=event.end_date,
|
||||
tags=event.tags,
|
||||
)
|
||||
|
||||
|
||||
class EventOutWithInterested(EventOut):
|
||||
interested: bool = False
|
||||
interested_count: int = 0
|
||||
|
@@ -253,7 +253,7 @@ async def read_events_count(authorize: Annotated[bool, Depends(permissions_check
|
||||
return response
|
||||
|
||||
|
||||
@router.get("/events/{item_id}", tags=["events"], response_model=events.Event)
|
||||
@router.get("/events/{item_id}", tags=["events"], response_model=events.EventOut)
|
||||
async def read_events_id(item_id : str, authorize: Annotated[bool, Depends(permissions_checker.PermissionChecker(roles=["Admin"]))]):
|
||||
event_repository = events.EventRepository(database=database.database)
|
||||
event = event_repository.find_one_by_id(ObjectId(item_id))
|
||||
|
Reference in New Issue
Block a user