Refactor event API and extend authentication utilities
Refactored the event API routes to improve error handling, add logging, and provide enhanced response structures with pagination. Updated tests to use new fixtures and include additional authentication utilities to facilitate testing with FastAPI's dependency injection. Also resolved issues with timezone awareness in event schemas.
This commit is contained in:
@@ -41,7 +41,7 @@ class EventBase(BaseModel):
|
||||
@field_validator('event_date')
|
||||
def validate_event_date(cls, v):
|
||||
if not v.tzinfo:
|
||||
raise ValueError("Event date must be timezone-aware")
|
||||
v = v.replace(tzinfo=timezone.utc)
|
||||
now = datetime.now(tz=timezone.utc)
|
||||
if v < now:
|
||||
raise ValueError("Event date cannot be in the past")
|
||||
@@ -81,7 +81,12 @@ class EventInDBBase(EventBase):
|
||||
|
||||
|
||||
class EventResponse(EventInDBBase):
|
||||
pass
|
||||
@field_validator('event_date')
|
||||
def validate_datetime(cls, v):
|
||||
if v.tzinfo is None:
|
||||
v.event_date = v.event_date.replace(tzinfo=timezone.utc)
|
||||
return v
|
||||
|
||||
|
||||
|
||||
class Event(EventInDBBase):
|
||||
|
||||
Reference in New Issue
Block a user