diff --git a/gestao/db/models/dependent.py b/gestao/db/models/dependent.py index 75d4722..b9fc7bf 100644 --- a/gestao/db/models/dependent.py +++ b/gestao/db/models/dependent.py @@ -13,8 +13,11 @@ class Meta(BaseMeta): id: str = ormar.String(max_length=200, primary_key=True) user_id: User = ormar.ForeignKey(User, ondelete=ormar.ReferentialAction.CASCADE) name: str = ormar.String(max_length=200) + cpf: str = ormar.String(max_length=200, unique=True) birth_date: date = ormar.Date() + gender: str = ormar.String(max_length=200) relationship: str = ormar.String(max_length=200) + deceased: bool = ormar.Boolean(default=False) created_at: datetime = ormar.DateTime(timezone=True, default=datetime.now) updated_at: datetime = ormar.DateTime( timezone=True, diff --git a/gestao/db/models/user.py b/gestao/db/models/user.py index 85ec5ac..2e068b5 100644 --- a/gestao/db/models/user.py +++ b/gestao/db/models/user.py @@ -10,30 +10,35 @@ class Meta(BaseMeta): tablename = "user" id: str = ormar.String(max_length=200, primary_key=True) + registration: str = ormar.String(max_length=200, unique=True) + password: str = ormar.String(max_length=200) name: str = ormar.String(max_length=200) + war_name: str = ormar.String(max_length=200) + birth_date: date = ormar.Date() + rg: str = ormar.String(max_length=200, unique=True) + rg_consignor: str = ormar.String(max_length=100) + rg_date: date = ormar.Date() + cpf: str = ormar.String(max_length=200, unique=True) + place_of_birth: str = ormar.String(max_length=200) + marital_status: str = ormar.String(max_length=200) + zipcode: str = ormar.String(max_length=100) address: str = ormar.String(max_length=200) neighborhood: str = ormar.String(max_length=200) city: str = ormar.String(max_length=100) state: str = ormar.String(max_length=100) - zipcode: str = ormar.String(max_length=100) - cpf: str = ormar.String(max_length=200, unique=True) - rg: str = ormar.String(max_length=200, unique=True) - birth_date: date = ormar.Date() - place_of_birth: str = ormar.String(max_length=200) - blood_type: str = ormar.String(max_length=200) + email: str = ormar.String(max_length=200) + phone: str = ormar.String(max_length=200) gender: str = ormar.String(max_length=200) father_name: str = ormar.String(max_length=200) - mother_date: str = ormar.String(max_length=200) - position: str = ormar.String(max_length=200) - occupancy: str = ormar.String(max_length=200) - admission_date: date = ormar.Date() - situation: str = ormar.String(max_length=200) - phone: str = ormar.String(max_length=200) - email: str = ormar.String(max_length=200) - marital_status: str = ormar.String(max_length=200) + mother_name: str = ormar.String(max_length=200) education: str = ormar.String(max_length=200) - registration: str = ormar.String(max_length=200, unique=True) + blood_type: str = ormar.String(max_length=200) + situation: str = ormar.String(max_length=200) + situation_obs: str = ormar.String(max_length=300) + admission_date: date = ormar.Date() role: str = ormar.String(max_length=200) + position: str = ormar.String(max_length=200) + occupancy: str = ormar.String(max_length=200) category: str = ormar.String(max_length=200) pattern: str = ormar.String(max_length=200) dispatcher: str = ormar.String(max_length=200) diff --git a/gestao/web/api/user/schema.py b/gestao/web/api/user/schema.py index 4086acb..6e310aa 100644 --- a/gestao/web/api/user/schema.py +++ b/gestao/web/api/user/schema.py @@ -6,68 +6,95 @@ class CreateUserDependentDTO(BaseModel): name: str + cpf: str birth_date: date + gender: str relationship: str + deceased: bool + + +class UpdateUserDependentDTO(BaseModel): + name: Optional[str] + cpf: Optional[str] + birth_date: Optional[date] + gender: Optional[str] + relationship: Optional[str] + deceased: Optional[bool] class CreateUserDTO(BaseModel): + registration: str + password: str name: str + war_name: str + birth_date: date + rg: str + rg_consignor: str + rg_date: date + cpf: str + place_of_birth: str + marital_status: str + zipcode: str address: str neighborhood: str city: str state: str - zipcode: str - cpf: str - rg: str - birth_date: date - place_of_birth: str - blood_type: str + email: str + phone: str gender: str father_name: str - mother_date: str - position: str - occupancy: str - admission_date: date - situation: str - phone: str - email: str - marital_status: str + mother_name: str education: str - registration: str - role: str - category: str - pattern: str - dispatcher: str - dispatched_date: date + blood_type: str + situation: str + situation_obs: Optional[str] + admission_date: Optional[date] + role: Optional[str] + position: Optional[str] + occupancy: Optional[str] + category: Optional[str] + pattern: Optional[str] + dispatcher: Optional[str] + dispatched_date: Optional[date] dependents: Optional[List[CreateUserDependentDTO]] class UpdateUserDTO(BaseModel): + registration: Optional[str] + password: Optional[str] name: Optional[str] + war_name: Optional[str] + birth_date: Optional[date] + rg: Optional[str] + rg_consignor: Optional[str] + rg_date: Optional[date] + cpf: Optional[str] + place_of_birth: Optional[str] + marital_status: Optional[str] + zipcode: Optional[str] address: Optional[str] neighborhood: Optional[str] city: Optional[str] state: Optional[str] - zipcode: Optional[str] - cpf: Optional[str] - rg: Optional[str] - birth_date: Optional[date] - place_of_birth: Optional[str] - blood_type: Optional[str] + email: Optional[str] + phone: Optional[str] gender: Optional[str] father_name: Optional[str] - mother_date: Optional[str] - position: Optional[str] - occupancy: Optional[str] - admission_date: Optional[date] - situation: Optional[str] - phone: Optional[str] - email: Optional[str] - marital_status: Optional[str] + mother_name: Optional[str] education: Optional[str] - registration: Optional[str] + blood_type: Optional[str] + situation: Optional[str] + situation_obs: Optional[str] + admission_date: Optional[date] role: Optional[str] + position: Optional[str] + occupancy: Optional[str] category: Optional[str] pattern: Optional[str] dispatcher: Optional[str] dispatched_date: Optional[date] + + +class AuthUserDTO(BaseModel): + registration: str + password: str diff --git a/gestao/web/api/user/views.py b/gestao/web/api/user/views.py index 98ed083..f17c051 100644 --- a/gestao/web/api/user/views.py +++ b/gestao/web/api/user/views.py @@ -6,7 +6,7 @@ from gestao.db.models.dependent import Dependent from gestao.db.models.user import User -from gestao.web.api.user.schema import CreateUserDTO, UpdateUserDTO +from gestao.web.api.user.schema import CreateUserDTO, UpdateUserDTO, AuthUserDTO router = APIRouter() @@ -77,3 +77,18 @@ async def delete_user(user_id: str) -> None: status_code=404, detail="Error occurred while deleting user", ) + + +@router.get("_auth/login") +async def user_auth(user_data: AuthUserDTO) -> User: + try: + user_data_dict = user_data.dict() + return await User.objects.get( + registration=user_data_dict['registration'], + password=user_data_dict['password'] + ) + except Exception: + logging.error("Error occurred in user_login", exc_info=True) + raise HTTPException(status_code=404, detail="Error occurred in user login") + +