Coverage for src/kwai/api/v1/trainings/schemas/coach.py: 87%
15 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"""Module that defines the JSON:API schemas for coaches."""
3from types import NoneType
5from pydantic import BaseModel
7from kwai.api.schemas.resources import CoachResourceIdentifier
8from kwai.core.json_api import Document, ResourceData
9from kwai.modules.training.coaches.coach import CoachEntity
12class CoachAttributes(BaseModel):
13 """Attributes for a coach JSON:API resource."""
15 name: str
18class CoachResource(CoachResourceIdentifier, ResourceData[CoachAttributes, NoneType]):
19 """A JSON:API resource for a coach."""
21 @classmethod
22 def create(cls, coach: CoachEntity) -> "CoachResource":
23 """Create a JSON:API resource from a coach entity."""
24 return CoachResource(
25 id=str(coach.id), attributes=CoachAttributes(name=str(coach.name))
26 )
29class CoachDocument(Document[CoachResource, NoneType]):
30 """A JSON:API document for one or more coaches."""
32 @classmethod
33 def create(cls, coach: CoachEntity) -> "CoachDocument":
34 """Create a document from a coach entity."""
35 return CoachDocument(data=CoachResource.create(coach))