63 lines
1.4 KiB
Python
63 lines
1.4 KiB
Python
import strawberry
|
|
from typing import List, Optional
|
|
from datetime import datetime
|
|
from strawberry.types import Info
|
|
|
|
from app.utils.format import get_image_url
|
|
|
|
@strawberry.type
|
|
class UserType:
|
|
id: str
|
|
email: str
|
|
name: str
|
|
avatar: str
|
|
handle: Optional[str]
|
|
|
|
# 互动统计字段
|
|
following_count: int
|
|
follower_count: int
|
|
|
|
# 统计汇总字段
|
|
owner_project_count: int
|
|
owner_likes_count: int
|
|
owner_favorites_count: int
|
|
owner_shares_count: int
|
|
|
|
admin_project_count: int
|
|
admin_likes_count: int
|
|
admin_favorites_count: int
|
|
admin_shares_count: int
|
|
|
|
user_project_count: int
|
|
user_likes_count: int
|
|
user_favorites_count: int
|
|
user_shares_count: int
|
|
|
|
created_at: datetime
|
|
|
|
# 动态解析字段:例如自动处理头像的绝对路径
|
|
@strawberry.field
|
|
def avatar_url(self) -> Optional[str]:
|
|
return get_image_url(self.avatar) if self.avatar else None
|
|
|
|
@strawberry.type
|
|
class WorkspaceMemberType:
|
|
id: strawberry.ID
|
|
workspace_id: str
|
|
user_id: Optional[str]
|
|
role: str
|
|
status: str
|
|
|
|
@strawberry.type
|
|
class WorkspaceType:
|
|
id: strawberry.ID
|
|
name: str
|
|
slug: str
|
|
logo: Optional[str]
|
|
description: Optional[str]
|
|
storage_used: int
|
|
|
|
# 支持前端按需加载关联的成员
|
|
@strawberry.field
|
|
def members(self, info: Info) -> List[WorkspaceMemberType]:
|
|
return info.context.members_loader.load(self.id) |