Coverage for src/schemas/contact.py: 100%

26 statements  

« prev     ^ index     » next       coverage.py v7.5.4, created at 2024-07-01 22:29 +0200

1from pydantic import BaseModel, ConfigDict, Field, EmailStr 

2from datetime import date 

3 

4from src.schemas.user import UserResponseSchema 

5 

6 

7class ContactSchema(BaseModel): 

8 first_name: str = Field(min_length=3, max_length=50) 

9 last_name: str = Field(min_length=3, max_length=50) 

10 email: EmailStr 

11 birthday: date 

12 additional_data: str = Field(max_length=250, json_schema_extra={"nullable": True}) 

13 

14 model_config = ConfigDict(from_attributes=True) 

15 

16 

17class ContactUpdateSchema(ContactSchema): 

18 first_name: str 

19 last_name: str 

20 email: EmailStr 

21 birthday: date 

22 additional_data: str 

23 

24 model_config = ConfigDict(from_attributes=True) 

25 

26 

27class ContactResponseSchema(BaseModel): 

28 id: int 

29 first_name: str 

30 last_name: str 

31 email: EmailStr 

32 birthday: date 

33 additional_data: str | None 

34 user: UserResponseSchema | None 

35 

36 model_config = ConfigDict(from_attributes=True)