Coverage for apps/kwai-api/src/kwai_api/v1/club/schemas/person.py: 100%

13 statements  

« prev     ^ index     » next       coverage.py v7.11.0, created at 2024-01-01 00:00 +0000

1"""Module for defining the JSON:API resource for a person.""" 

2 

3from typing import Annotated 

4 

5from kwai_core.json_api import Relationship, ResourceMeta 

6from pydantic import BaseModel, Field 

7 

8from kwai_api.v1.club.schemas.contact import ContactResource 

9from kwai_api.v1.club.schemas.resources import ( 

10 ContactResourceIdentifier, 

11 PersonResourceIdentifier, 

12) 

13from kwai_api.v1.schemas import ( 

14 CountryResource, 

15 CountryResourceIdentifier, 

16) 

17 

18 

19class PersonAttributes(BaseModel): 

20 """Attributes for the person JSON:API resource.""" 

21 

22 first_name: str 

23 last_name: str 

24 gender: int 

25 birthdate: str 

26 remark: str 

27 

28 

29class PersonRelationships(BaseModel): 

30 """Relationships of a person JSON:API resource.""" 

31 

32 contact: Relationship[ContactResourceIdentifier] 

33 nationality: Relationship[CountryResourceIdentifier] 

34 

35 

36class PersonResource(PersonResourceIdentifier): 

37 """A JSON:API resource for a person.""" 

38 

39 meta: ResourceMeta | None = None 

40 attributes: PersonAttributes 

41 relationships: PersonRelationships 

42 

43 

44PersonInclude = Annotated[ 

45 ContactResource | CountryResource, Field(discriminator="type") 

46] 

47 

48 

49class PersonDocument(BaseModel): 

50 """A JSON:API document for one person.""" 

51 

52 data: PersonResource 

53 included: set[PersonInclude] = Field(default_factory=set)