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
|
2022-12-08 02:49:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
class Token(BaseModel):
|
|
|
|
access_token: str
|
|
|
|
token_type: str
|
|
|
|
|
|
|
|
|
|
|
|
class TokenData(BaseModel):
|
2022-12-08 12:18:59 +03:00
|
|
|
email: EmailStr
|
2022-12-08 02:49:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
class UserBase(BaseModel):
|
2022-12-08 12:18:59 +03:00
|
|
|
email: EmailStr
|
2022-12-08 02:49:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
class UserLogin(UserBase):
|
|
|
|
password: str
|
|
|
|
|
|
|
|
|
|
|
|
class UserCreate(UserBase):
|
|
|
|
password: str
|
|
|
|
fullname: str
|
2022-12-08 12:18:59 +03:00
|
|
|
gender: str
|
|
|
|
born: datetime
|
2022-12-08 02:49:23 +03:00
|
|
|
|
|
|
|
|
|
|
|
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
|
2022-12-08 02:49:23 +03:00
|
|
|
|
|
|
|
class Config:
|
|
|
|
orm_mode = True
|
|
|
|
|
|
|
|
|
|
|
|
class User(UserBase):
|
|
|
|
id: int
|
2022-12-08 12:18:59 +03:00
|
|
|
fullname: str
|
2022-12-08 02:49:23 +03:00
|
|
|
hashed_password: str
|
|
|
|
disabled: bool
|
2022-12-08 03:27:15 +03:00
|
|
|
is_manager: bool
|
2022-12-08 02:49:23 +03:00
|
|
|
|
|
|
|
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
|