Skip to content

Commit

Permalink
Applying Models in Configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Oct 29, 2024
1 parent 450516c commit 185ce21
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 21 deletions.
4 changes: 4 additions & 0 deletions app/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class LoginErrorEnum(str, Enum):
INACTIVE_EMPLOYEE = "inactive_employee"
REQUIRE_2FA = "require_2fa"

class AcceptTermsEnum(str, Enum):
SUCCESS = "success"
FAILURE = "failure"


class AccessErrorEnum(str, Enum):
NOT_FOUND = "NOT_FOUND"
Expand Down
58 changes: 39 additions & 19 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from typing import Annotated, List
from fastapi import APIRouter, Depends, Request
from fastapi_limiter.depends import RateLimiter
from fastapi.responses import JSONResponse

from app.decorators import router_request
from app.dependencies import assert_user_is_active, assert_cpf_is_valid
Expand All @@ -14,6 +15,7 @@
Encounter,
UserInfo,
)
from app.types.errors import AcceptTermsEnum
from app.utils import read_bq, validate_user_access_to_patient_data
from app.config import (
BIGQUERY_PROJECT,
Expand All @@ -24,7 +26,8 @@
REQUEST_LIMIT_WINDOW_SIZE,
)
from app.types.errors import (
AccessErrorModel
AccessErrorModel,
TermAcceptanceErrorModel
)

router = APIRouter(prefix="/frontend", tags=["Frontend Application"])
Expand All @@ -51,6 +54,41 @@ async def get_user_info(
}


@router_request(
method="POST",
router=router,
path="/user/accept-terms/",
response_model=TermAcceptanceErrorModel,
responses={
500: {"model": TermAcceptanceErrorModel},
},
)
async def accept_use_terms(
user: Annotated[User, Depends(assert_user_is_active)],
request: Request,
) -> TermAcceptanceErrorModel:

try:
user.is_use_terms_accepted = True
user.use_terms_accepted_at = datetime.datetime.now()
await user.save()
return JSONResponse(
status_code=200,
content={
"message": "Success",
"type": AcceptTermsEnum.SUCCESS,
},
)
except Exception:
return JSONResponse(
status_code=500,
content={
"message": "Patient not found",
"type": AcceptTermsEnum.FAILURE,
},
)


@router_request(
method="GET",
router=router,
Expand Down Expand Up @@ -152,24 +190,6 @@ async def get_patient_encounters(
return []


@router_request(
method="POST",
router=router,
path="/user/accept-terms/",
response_model=bool,
)
async def accept_use_terms(
user: Annotated[User, Depends(assert_user_is_active)],
request: Request,
) -> List[Encounter]:

user.is_use_terms_accepted = True
user.use_terms_accepted_at = datetime.datetime.now()
await user.save()

return user


@router.get("/patient/filter_tags")
async def get_filter_tags(_: Annotated[User, Depends(assert_user_is_active)]) -> List[str]:
return [
Expand Down
10 changes: 8 additions & 2 deletions app/types/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

from app.enums import (
LoginErrorEnum,
AccessErrorEnum
AccessErrorEnum,
AcceptTermsEnum
)


Expand All @@ -14,4 +15,9 @@ class AuthenticationErrorModel(BaseModel):

class AccessErrorModel(BaseModel):
message: str
type: AccessErrorEnum
type: AccessErrorEnum


class TermAcceptanceErrorModel(BaseModel):
message: str
type: AcceptTermsEnum

0 comments on commit 185ce21

Please sign in to comment.