- C-01: Wrap connection request flush in IntegrityError handler for TOCTOU race on partial unique index - W-02: Extract ntfy config into plain dict before commit to avoid DetachedInstanceError in background tasks - W-04: Add integer range validation (1–2147483647) on notification IDs - W-07: Add typed response models for respond_to_request endpoint - W-09: Document resolved_at requirement for future cancel endpoint - S-02: Use Literal type for ConnectionRequestResponse.status - S-04: Check ntfy master switch in extract_ntfy_config - S-05: Move date import to module level in connection service Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from pydantic import BaseModel, ConfigDict, Field, field_validator
|
|
from datetime import datetime
|
|
from typing import Optional
|
|
|
|
|
|
class NotificationResponse(BaseModel):
|
|
id: int
|
|
user_id: int
|
|
type: str
|
|
title: Optional[str] = None
|
|
message: Optional[str] = None
|
|
data: Optional[dict] = None
|
|
source_type: Optional[str] = None
|
|
source_id: Optional[int] = None
|
|
is_read: bool
|
|
created_at: datetime
|
|
|
|
model_config = ConfigDict(from_attributes=True)
|
|
|
|
|
|
class NotificationListResponse(BaseModel):
|
|
notifications: list[NotificationResponse]
|
|
unread_count: int
|
|
total: int
|
|
|
|
|
|
class MarkReadRequest(BaseModel):
|
|
model_config = ConfigDict(extra="forbid")
|
|
|
|
notification_ids: list[int] = Field(..., min_length=1, max_length=100, json_schema_extra={"items": {"minimum": 1, "maximum": 2147483647}})
|
|
|
|
@field_validator('notification_ids')
|
|
@classmethod
|
|
def validate_ids(cls, v: list[int]) -> list[int]:
|
|
for i in v:
|
|
if i < 1 or i > 2147483647:
|
|
raise ValueError('Each notification ID must be between 1 and 2147483647')
|
|
return v
|