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

Implement Rate Limiter #222

Merged
merged 1 commit into from
Sep 2, 2024
Merged
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
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
Loading