backend/med_backend/auth/schemas.py

65 lines
1.1 KiB
Python
Raw Permalink Normal View History

2022-12-09 16:40:14 +03:00
from datetime import date, datetime
2022-12-08 12:18:59 +03:00
2022-12-09 16:40:14 +03:00
from dateutil.relativedelta import relativedelta
from pydantic import BaseModel, EmailStr, root_validator
class Token(BaseModel):
access_token: str
token_type: str
class TokenData(BaseModel):
2022-12-08 12:18:59 +03:00
email: EmailStr
class UserBase(BaseModel):
2022-12-08 12:18:59 +03:00
email: EmailStr
class UserLogin(UserBase):
password: str
class UserCreate(UserBase):
password: str
fullname: str
2022-12-08 12:18:59 +03:00
gender: str
born: datetime
class UserPublicInfo(UserBase):
id: int
fullname: str | None
disabled: bool
2022-12-09 16:40:14 +03:00
born: date
@root_validator(pre=False)
def _set_fields(cls, values):
values["age"] = relativedelta(datetime.now(), values["born"]).years
values.pop("born")
return values
class Config:
orm_mode = True
class User(UserBase):
id: int
2022-12-08 12:18:59 +03:00
fullname: str
hashed_password: str
disabled: bool
2022-12-08 03:27:15 +03:00
is_manager: bool
class Config:
orm_mode = True
2022-12-09 14:40:57 +03:00
class UpdateUserBase(UserBase):
fullname: str
class UpdateUserProfile(UpdateUserBase):
disabled: bool
is_manager: bool