Skip to content

Commit

Permalink
Implement Rate Limiter
Browse files Browse the repository at this point in the history
  • Loading branch information
TanookiVerde committed Sep 2, 2024
1 parent d3d0740 commit b0f8900
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
10 changes: 8 additions & 2 deletions app/routers/frontend.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*-
from typing import Annotated, List
from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Request
from tortoise.exceptions import ValidationError

from fastapi_simple_rate_limiter import rate_limiter
from app.dependencies import (
get_current_frontend_user
)
Expand Down Expand Up @@ -45,9 +45,11 @@ async def get_user_info(


@router.get("/patient/header/{cpf}")
@rate_limiter(limit=5, seconds=60)
async def get_patient_header(
_: Annotated[User, Depends(get_current_frontend_user)],
cpf: str,
request: Request,
) -> PatientHeader:
validator = CPFValidator()
try:
Expand Down Expand Up @@ -79,9 +81,11 @@ async def get_patient_header(


@router.get("/patient/summary/{cpf}")
@rate_limiter(limit=5, seconds=60)
async def get_patient_summary(
_: Annotated[User, Depends(get_current_frontend_user)],
cpf: str,
request: Request,
) -> PatientSummary:

results = await read_bq(
Expand Down Expand Up @@ -114,9 +118,11 @@ async def get_filter_tags(


@router.get("/patient/encounters/{cpf}")
@rate_limiter(limit=5, seconds=60)
async def get_patient_encounters(
_: Annotated[User, Depends(get_current_frontend_user)],
cpf: str,
request: Request,
) -> List[Encounter]:

results = await read_bq(
Expand Down
4 changes: 2 additions & 2 deletions app/types/frontend.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ def __init__(
self,
username: str,
password: str,
totp: str,
totp_code: str,
):
super().__init__(username=username, password=password)
self.totp = totp
self.totp_code = totp_code


# Clinic Family model
Expand Down
34 changes: 33 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ nltk = "^3.9.1"
asyncer = "^0.0.8"
qrcode = "^7.4.2"
pyotp = "^2.9.0"
fastapi-simple-rate-limiter = "^0.0.4"


[tool.poetry.group.dev.dependencies]
Expand Down

0 comments on commit b0f8900

Please sign in to comment.