Files
Zayden-Jung 61e3d71b72 make a media api, encapsulate the original S3 bucket address
there are 3 parts, from back to head, url inside the bucket -> url of backend media api -> backend domain, only the last part is spliced by frontend, the other two parts are spliced with sqlalchemy
2026-05-20 17:31:49 +08:00

67 lines
1.6 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
from app.models.user import User
@strawberry.type
class UserType:
id: str
email: str
name: str
handle: Optional[str]
@strawberry.field
def avatar(self, root: User) -> Optional[str]:
return root.avatar_url
# 互动统计字段
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)