refactor: 重整 schemas 作用域并统一用户上下文模型
This commit is contained in:
@@ -1,15 +1,12 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import ClassVar, Literal
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import BaseModel, ConfigDict, Field
|
||||
|
||||
|
||||
class UserBasicInfo(BaseModel):
|
||||
id: str
|
||||
username: str
|
||||
avatar_url: str | None = None
|
||||
from schemas.user.context import UserContext
|
||||
|
||||
|
||||
class FriendRequestCreate(BaseModel):
|
||||
@@ -21,8 +18,8 @@ class FriendRequestCreate(BaseModel):
|
||||
|
||||
class FriendRequestResponse(BaseModel):
|
||||
id: UUID
|
||||
sender: UserBasicInfo
|
||||
recipient: UserBasicInfo
|
||||
sender: UserContext
|
||||
recipient: UserContext
|
||||
content: str | None
|
||||
status: Literal["pending", "accepted", "rejected", "canceled"]
|
||||
created_at: datetime
|
||||
@@ -30,7 +27,7 @@ class FriendRequestResponse(BaseModel):
|
||||
|
||||
class FriendResponse(BaseModel):
|
||||
id: UUID
|
||||
friend: UserBasicInfo
|
||||
friend: UserContext
|
||||
status: Literal["active"]
|
||||
created_at: datetime
|
||||
accepted_at: datetime | None
|
||||
|
||||
@@ -22,7 +22,7 @@ from v1.users.repository import UserRepository
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from v1.friendships.schemas import UserBasicInfo
|
||||
from schemas.user.context import UserContext
|
||||
|
||||
|
||||
logger = get_logger("v1.friendships.service")
|
||||
@@ -555,14 +555,14 @@ class FriendshipService(BaseService):
|
||||
accepted_at=friendship.updated_at,
|
||||
)
|
||||
|
||||
def _build_user_basic_info(self, profile: Any) -> "UserBasicInfo":
|
||||
from v1.friendships.schemas import UserBasicInfo
|
||||
def _build_user_basic_info(self, profile: Any) -> "UserContext":
|
||||
from schemas.user.context import UserContext
|
||||
|
||||
if profile is None:
|
||||
return UserBasicInfo(id="", username="")
|
||||
return UserContext(id="", username="")
|
||||
|
||||
p = profile # type: ignore[assignment]
|
||||
return UserBasicInfo(
|
||||
return UserContext(
|
||||
id=str(p.id),
|
||||
username=p.username,
|
||||
avatar_url=p.avatar_url if hasattr(p, "avatar_url") else None,
|
||||
|
||||
Reference in New Issue
Block a user