Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/login route #6

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions gestao/db/models/dependent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
35 changes: 20 additions & 15 deletions gestao/db/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
97 changes: 62 additions & 35 deletions gestao/web/api/user/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 16 additions & 1 deletion gestao/web/api/user/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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")


Loading