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

1"""Module that defines the JSON:API schemas for coaches.""" 

2 

3from types import NoneType 

4 

5from pydantic import BaseModel 

6 

7from kwai.api.schemas.resources import CoachResourceIdentifier 

8from kwai.core.json_api import Document, ResourceData 

9from kwai.modules.training.coaches.coach import CoachEntity 

10 

11 

12class CoachAttributes(BaseModel): 

13 """Attributes for a coach JSON:API resource.""" 

14 

15 name: str 

16 

17 

18class CoachResource(CoachResourceIdentifier, ResourceData[CoachAttributes, NoneType]): 

19 """A JSON:API resource for a coach.""" 

20 

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 ) 

27 

28 

29class CoachDocument(Document[CoachResource, NoneType]): 

30 """A JSON:API document for one or more coaches.""" 

31 

32 @classmethod 

33 def create(cls, coach: CoachEntity) -> "CoachDocument": 

34 """Create a document from a coach entity.""" 

35 return CoachDocument(data=CoachResource.create(coach))