2026-01-06 10:04:06 +00:00
|
|
|
"""
|
|
|
|
|
通知相关的 Pydantic Schema
|
|
|
|
|
"""
|
|
|
|
|
from pydantic import BaseModel, Field
|
2026-01-23 07:00:03 +00:00
|
|
|
from typing import Optional, List, Union
|
2026-01-06 10:04:06 +00:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationBase(BaseModel):
|
|
|
|
|
type: str = "info"
|
|
|
|
|
category: str = "system"
|
|
|
|
|
title: str
|
|
|
|
|
content: Optional[str] = None
|
|
|
|
|
link: Optional[str] = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationCreate(NotificationBase):
|
|
|
|
|
user_id: int
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationUpdate(BaseModel):
|
2026-01-23 07:00:03 +00:00
|
|
|
is_read: Optional[bool] = None
|
2026-01-06 10:04:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class NotificationResponse(NotificationBase):
|
2026-01-23 07:00:03 +00:00
|
|
|
id: Union[str, int]
|
2026-01-06 10:04:06 +00:00
|
|
|
user_id: int
|
2026-01-23 07:00:03 +00:00
|
|
|
is_read: bool
|
|
|
|
|
created_at: Union[datetime, float] # Redis returns float timestamp
|
2026-01-06 10:04:06 +00:00
|
|
|
read_at: Optional[datetime] = None
|
|
|
|
|
|
|
|
|
|
class Config:
|
|
|
|
|
from_attributes = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class UnreadCountResponse(BaseModel):
|
2026-01-23 07:00:03 +00:00
|
|
|
unread_count: int
|