Coverage for src/kwai/api/v1/auth/schemas/user_account.py: 92%
12 statements
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
« prev ^ index » next coverage.py v7.6.10, created at 2024-01-01 00:00 +0000
1"""Schemas for a user account resource."""
3from typing import Self
5from pydantic import BaseModel
7from kwai.api.v1.auth.schemas.resources import UserAccountResourceIdentifier
8from kwai.core.json_api import Document, ResourceData
9from kwai.modules.identity.users.user_account import UserAccountEntity
12class UserAccountAttributes(BaseModel):
13 """Attributes of a user account JSON:API resource."""
15 email: str
18class UserAccountResource(
19 UserAccountResourceIdentifier, ResourceData[UserAccountAttributes, None]
20):
21 """A JSON:API resource for a user account."""
24class UserAccountDocument(Document[UserAccountResource, None]):
25 """A JSON:API document for a user account."""
27 @classmethod
28 def create(cls, user_account: UserAccountEntity) -> Self:
29 """Create a document for a user account."""
30 return cls(
31 data=UserAccountResource(
32 id=str(user_account.id),
33 attributes=UserAccountAttributes(email=str(user_account.user.email)),
34 )
35 )