-
Notifications
You must be signed in to change notification settings - Fork 264
Expand file tree
/
Copy pathprofiles.py
More file actions
64 lines (51 loc) · 1.46 KB
/
profiles.py
File metadata and controls
64 lines (51 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from datetime import date
from typing import Any
from fastapi import UploadFile, Form, File, HTTPException
from pydantic import BaseModel, field_validator, HttpUrl, ConfigDict
from typing_extensions import Self
from database.models.accounts import GenderEnum
from validation import (
validate_name,
validate_image,
validate_gender,
validate_birth_date
)
from validation.profile import validate_info
class ProfileBaseSchema(BaseModel):
first_name: str
last_name: str
gender: str
date_of_birth: date
info: str
class ProfileRequestSchema(ProfileBaseSchema):
avatar: UploadFile
@field_validator("first_name", "last_name")
@classmethod
def validate_first_last_name(cls, value):
validate_name(value)
return value
@field_validator("gender")
@classmethod
def validate_gender(cls, value):
validate_gender(value)
return value
@field_validator("date_of_birth")
@classmethod
def validate_date_of_birth(cls, value):
validate_birth_date(value)
return value
@field_validator("info")
@classmethod
def validate_info(cls, value):
validate_info(value)
return value
@field_validator("avatar")
@classmethod
def validate_avatar(cls, value):
validate_image(value)
return value
class ProfileResponseSchema(ProfileBaseSchema):
model_config = ConfigDict(from_attributes=True)
id: int
user_id: int
avatar: str