fix: 修复后端代码违规并更新协议文档
- 修复 notifications 模块 datetime.now() 缺少时区问题 - 用 ApiProblemError 替换 BaseService 中的 HTTPException - 更新协议文档:添加错误码、繁体字段、邀请相关协议 - 升级 Docker 镜像版本
This commit is contained in:
@@ -2,9 +2,8 @@ from __future__ import annotations
|
||||
|
||||
from uuid import UUID
|
||||
|
||||
from fastapi import HTTPException
|
||||
|
||||
from core.auth.models import CurrentUser
|
||||
from core.http.errors import ApiProblemError, problem_payload
|
||||
|
||||
|
||||
class BaseService:
|
||||
@@ -15,7 +14,10 @@ class BaseService:
|
||||
|
||||
def require_current_user(self) -> CurrentUser:
|
||||
if self._current_user is None:
|
||||
raise HTTPException(status_code=401, detail="Unauthorized")
|
||||
raise ApiProblemError(
|
||||
status_code=401,
|
||||
detail=problem_payload(code="AUTH_UNAUTHORIZED", detail="Unauthorized"),
|
||||
)
|
||||
return self._current_user
|
||||
|
||||
def require_user_id(self) -> UUID:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from uuid import UUID
|
||||
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
@@ -85,7 +85,7 @@ class NotificationRepository:
|
||||
if un is None:
|
||||
return False
|
||||
un.is_read = True
|
||||
un.read_at = datetime.now()
|
||||
un.read_at = datetime.now(timezone.utc)
|
||||
await self._session.flush()
|
||||
return True
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from uuid import UUID
|
||||
|
||||
from core.http.errors import ApiProblemError, problem_payload
|
||||
@@ -113,7 +113,7 @@ class NotificationService:
|
||||
body=n.body,
|
||||
payload=payload,
|
||||
is_read=True,
|
||||
read_at=un.read_at or datetime.now(),
|
||||
read_at=un.read_at or datetime.now(timezone.utc),
|
||||
created_at=un.created_at,
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user